/** 设置显示的图片 */ public void setImage(int[] res) { imgIds = res; linearLayout = (LinearLayout) findViewById(R.id.viewGroup); tips = new ImageView[imgIds.length]; for (int i = 0; i < imgIds.length; i++) { ImageView mImageView = new ImageView(mContext); tips[i] = mImageView; LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); layoutParams.rightMargin = AppUtil.dip2px(mContext, 4); layoutParams.leftMargin = AppUtil.dip2px(mContext, 4); layoutParams.width = AppUtil.dip2px(mContext, 7); layoutParams.height = AppUtil.dip2px(mContext, 7); mImageView.setBackgroundResource(R.drawable.page_indicator_unfocused); linearLayout.addView(mImageView, layoutParams); } // 这个我是从上一个界面传过来的,上一个界面是一个GridView mImageSwitcher.setImageResource(imgIds[currentPosition]); setImageBackground(currentPosition); }
@SuppressLint("InflateParams") @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(context).inflate(R.layout.user_item, null); ItemViewCache itemViewCache = new ItemViewCache(); itemViewCache.imageViewUser = (ImageView) convertView.findViewById(R.id.imageViewUser); itemViewCache.textViewUser = (TextView) convertView.findViewById(R.id.textViewUser); itemViewCache.textViewCount = (TextView) convertView.findViewById(R.id.textViewCount); itemViewCache.textViewDate = (TextView) convertView.findViewById(R.id.textViewDate); convertView.setTag(itemViewCache); } ItemViewCache cache = (ItemViewCache) convertView.getTag(); User user = userList.get(position); URL url = user.getUserAvatar(); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(128, 128); layoutParams.leftMargin = 5; layoutParams.rightMargin = 5; layoutParams.topMargin = 5; layoutParams.bottomMargin = 5; cache.imageViewUser.setLayoutParams(layoutParams); if (url != null) { imageLoader.displayImage(url.toString(), cache.imageViewUser); } cache.textViewUser.setText(user.getTitle()); cache.textViewCount.setText("随笔总数:" + user.getPostCount()); cache.textViewDate.setText("最后更新:" + AppUtils.parseDateToString(user.getUpdatedDate())); return convertView; }
private void init(Context context) { inflater = LayoutInflater.from(context); view = inflater.inflate(R.layout.cs_message_about, null); LinearLayout.LayoutParams param_view = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); param_view.leftMargin = DisplayManager.GetInstance().changeWidthSize(30); param_view.rightMargin = DisplayManager.GetInstance().changeWidthSize(30); param_view.topMargin = DisplayManager.GetInstance().changeWidthSize(20); view.setLayoutParams(param_view); version_title = (TextView) view.findViewById(R.id.version_title); version_content = (TextView) view.findViewById(R.id.version_content); help_title = (TextView) view.findViewById(R.id.help_title); help_title.setFocusable(true); help_title.setFocusableInTouchMode(true); help_content = (TextView) view.findViewById(R.id.help_content); version_title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE); version_content.setTextSize(TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE); help_title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE); help_content.setTextSize(TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE); version_title.setText("版本信息"); version_content.setText("当前版本:" + Config.GetInstance().getVersionDisplayText()); help_title.setText("使用帮助"); addView(view); setContentData(getHelpContent(Config.OemType.getOemType(Config.GetInstance().getOemType()))); }
void initControl(Context ctx) { this.setBackground(ctx.getResources().getDrawable(R.drawable.sticky_note_background)); this.setWeightSum(1.0f); this.setOrientation(LinearLayout.VERTICAL); writingCanvas = new NoteWritingCanvas(ctx); LinearLayout.LayoutParams writingCanvasLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 0.95f); writingCanvasLayoutParams.topMargin = 5; writingCanvasLayoutParams.leftMargin = 2; writingCanvasLayoutParams.rightMargin = 2; writingCanvas.setLayoutParams(writingCanvasLayoutParams); writingCanvas.setWritingEventListener(this); this.addView(writingCanvas); okButton = new Button(ctx); okButton.setBackgroundResource(R.drawable.ok_button); LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams(75, 75); buttonLayoutParams.gravity = Gravity.BOTTOM | Gravity.END; okButton.setLayoutParams(buttonLayoutParams); okButton.setEnabled(false); okButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub okButton.setEnabled(false); if (contentSubmittedListener != null) { contentSubmittedListener.contentSubmittedEventHandler(myself); } } }); this.addView(okButton); }
/** Show find dialog. Very pretty UI code ;) */ public void showFindDialog() { Log.d(TAG, "find dialog..."); final Dialog dialog = new Dialog(this); dialog.setTitle(R.string.find_dialog_title); LinearLayout contents = new LinearLayout(this); contents.setOrientation(LinearLayout.VERTICAL); this.findTextInputField = new EditText(this); this.findTextInputField.setWidth(this.pagesView.getWidth() * 80 / 100); Button goButton = new Button(this); goButton.setText(R.string.find_go_button); goButton.setOnClickListener( new OnClickListener() { public void onClick(View v) { String text = OpenFileActivity.this.findTextInputField.getText().toString(); OpenFileActivity.this.findText(text); dialog.dismiss(); } }); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.leftMargin = 5; params.rightMargin = 5; params.bottomMargin = 2; params.topMargin = 2; contents.addView(findTextInputField, params); contents.addView(goButton, params); dialog.setContentView(contents); dialog.show(); }
private void addTextView() { removeAllViews(); if (mIndexListSize < 1) { return; } TextView tmpTV; for (double i = 1; i <= mIndexListSize; i++) { String tmpAlphabet = mAlphabetList.get((int) i - 1).firstAlphabet; tmpTV = new TextView(getContext()); tmpTV.setText(tmpAlphabet); tmpTV.setGravity(Gravity.CENTER); tmpTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, mAlphabetTextSize); tmpTV.setTextColor(Color.BLACK); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1); params.leftMargin = mAlphabetLeftMargin; tmpTV.setLayoutParams(params); tmpTV.setIncludeFontPadding(false); addView(tmpTV); } }
/** 初始化Column栏目项 */ private void initTabColumn() { mRadioGroup_content.removeAllViews(); if (mUserChannelList != null) { int count = mUserChannelList.size(); mColumnHorizontalScrollView.setParam( getActivity(), mScreenWidth, mRadioGroup_content, mShadeleft, mShaderight, ll_more_columns, rl_column); for (int i = 0; i < count; i++) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.leftMargin = 5; params.rightMargin = 5; // TextView localTextView = (TextView) mInflater.inflate(R.layout.column_radio_item, // null); TextView columnTextView = new TextView(getActivity()); columnTextView.setTextAppearance(getActivity(), R.style.top_category_scroll_view_item_text); // // localTextView.setBackground(getResources().getDrawable(R.drawable.top_category_scroll_text_view_bg)); columnTextView.setBackgroundResource(R.drawable.radio_buttong_bg); columnTextView.setGravity(Gravity.CENTER); columnTextView.setPadding(5, 5, 5, 5); columnTextView.setId(i); columnTextView.setText(mUserChannelList.get(i).getName()); columnTextView.setTextColor( getResources().getColorStateList(R.color.top_category_scroll_text_color_day)); if (columnSelectIndex == i) { columnTextView.setSelected(true); } columnTextView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { for (int i = 0; i < mRadioGroup_content.getChildCount(); i++) { View localView = mRadioGroup_content.getChildAt(i); if (localView != v) localView.setSelected(false); else { localView.setSelected(true); mViewPager.setCurrentItem(i); } } Toast.makeText( getActivity().getApplicationContext(), mUserChannelList.get(v.getId()).getName(), Toast.LENGTH_SHORT) .show(); } }); mRadioGroup_content.addView(columnTextView, i, params); } } }
@Override public void onClick(View view) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ivTabLine.getLayoutParams(); if (view.getId() == R.id.id_tab_user_app_ll) { mPageVp.setCurrentItem(2); lp.leftMargin = (int) (screenWidth * 2.0 / 3); } else if (view.getId() == R.id.id_tab_sys_app_ll) { mPageVp.setCurrentItem(1); lp.leftMargin = (int) (screenWidth * 1.0 / 3); } else if (view.getId() == R.id.id_tab_all_app_ll) { mPageVp.setCurrentItem(0); lp.leftMargin = 0; } ivTabLine.setLayoutParams(lp); }
/** * Generate layout params for grid item view with appropriate horizontal spacing. The vertical * spacing between grid items should be set by the list's divider height. The grid's top and * bottom margins can be set on the list by enabling header and footer dividers or by disabling * clipToPadding and setting bottom padding on the listview */ private LinearLayout.LayoutParams getGridItemLayoutParams(int column) { LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1); lp.leftMargin = (column == 0 ? gridItemHorizontalSpacing : gridItemHorizontalSpacing / 2); lp.rightMargin = (column == numColumns - 1 ? gridItemHorizontalSpacing : gridItemHorizontalSpacing / 2); lp.topMargin = 0; lp.bottomMargin = 0; // rely on the list divider for vertical spacing between rows return lp; }
@Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_MOVE: LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(iconSize, iconSize); lp.leftMargin = (int) event.getRawX() - iconSize / 2; lp.topMargin = (int) event.getRawY() - iconSize / 2; v.setLayoutParams(lp); } return true; }
/** * 获取移动的VIEW,放入对应ViewGroup布局容器 * * @param viewGroup * @param view * @param initLocation * @return */ private View getMoveView(ViewGroup viewGroup, View view, int[] initLocation) { int x = initLocation[0]; int y = initLocation[1]; viewGroup.addView(view); LinearLayout.LayoutParams mLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); mLayoutParams.leftMargin = x; mLayoutParams.topMargin = y; view.setLayoutParams(mLayoutParams); return view; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // создание LinearLayout LinearLayout linLayout = new LinearLayout(this); // установим вертикальную ориентацию linLayout.setOrientation(LinearLayout.VERTICAL); // создаем LayoutParams LayoutParams linLayoutParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); // устанавливаем linLayout как корневой элемент экрана setContentView(linLayout, linLayoutParam); LayoutParams lpView = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); TextView tv = new TextView(this); tv.setText("TextView"); tv.setLayoutParams(lpView); linLayout.addView(tv); Button btn = new Button(this); btn.setText("Button"); linLayout.addView(btn, lpView); LinearLayout.LayoutParams leftMarginParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); leftMarginParams.leftMargin = 50; Button btn1 = new Button(this); btn1.setText("Button1"); linLayout.addView(btn1, leftMarginParams); LinearLayout.LayoutParams rightGravityParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); rightGravityParams.gravity = Gravity.RIGHT; Button btn2 = new Button(this); btn2.setText("Button2"); linLayout.addView(btn2, rightGravityParams); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); lp.weight = 1; Button b = new Button(this); b.setText("bbbb"); linLayout.addView(b, lp); EditText et = new EditText(this); et.setText("dd"); linLayout.addView(et, lp); }
private void initDatas() { code = SearchFragment.positionsClassCode; value = SearchFragment.positionsClassValue; if (PositionClassifyController.positionClassifies != null && PositionClassifyController.positionClassifies.size() > 0) { int n = PositionClassifyController.positionClassifies.size(); for (int i = 0; i < n; i++) { final PositionClassify positionClassify = PositionClassifyController.positionClassifies.get(i); final PositionClassItemView positionView = new PositionClassItemView(context); positionView.setPositionClassify(positionClassify); positionView.setOnItemClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (positionClassify.isHasSub()) { showSubAddressViews(positionClassify); } else { boolean flag = positionView.getCheckedStatus(); positionView.setCheckedStatus(!flag); if (!flag) { code = positionClassify.getCode(); value = positionClassify.getValue(); startIntent(); finish(); } else { code = ""; value = ""; } } } }); linear_main.addView(positionView); if (i < n - 1) { View line = LayoutInflater.from(context).inflate(R.layout.layout_line, null); linear_main.addView(line, params); } else { params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.height = 1; params.leftMargin = 1; params.bottomMargin = 10; View line = LayoutInflater.from(context).inflate(R.layout.layout_line, null); linear_main.addView(line, params); } } } }
public static void resetLL(View... view) { float rote = Handler_System.getWidthRoate(ApplicationBean.getApplication().getMode_w()); if (view == null || rote == 1) { return; } for (View view2 : view) { LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view2.getLayoutParams(); layoutParams.leftMargin = (int) (layoutParams.leftMargin * rote); layoutParams.rightMargin = (int) (layoutParams.rightMargin * rote); layoutParams.topMargin = (int) (layoutParams.topMargin * rote); layoutParams.bottomMargin = (int) (layoutParams.bottomMargin * rote); view2.setLayoutParams(layoutParams); } }
private void initComponent() { imageViewAvatar = (ImageView) findViewById(R.id.imageViewUserAvatar); textViewUserName = (TextView) findViewById(R.id.textViewUserName); textViewUpdate = (TextView) findViewById(R.id.textViewUserUpdate); textViewUri = (TextView) findViewById(R.id.textViewUserUri); // listViewBlogList = (ListView) findViewById(R.id.listViewUserBlogList); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(128, 128); layoutParams.leftMargin = 15; layoutParams.topMargin = 15; layoutParams.rightMargin = 15; layoutParams.bottomMargin = 15; imageViewAvatar.setLayoutParams(layoutParams); }
public TextView getTitle(Context ctx) { title = new TextView(ctx); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); p.leftMargin = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 10, ctx.getResources().getDisplayMetrics()); title.setLayoutParams(p); title.setText(this.getNameQuestion()); title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); return title; }
/** * 通用右侧图标 最大3个 * * @param resIds 图标资源数组 * @param onRightImagesClickListener 点击的回调 */ public void initRightImages(int[] resIds, View.OnClickListener onRightImagesClickListener) { LinearLayout rightLl = (LinearLayout) findViewById(R.id.ll_common_right); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.leftMargin = 10; rightLl.setOrientation(LinearLayout.HORIZONTAL); // 默认为横向 for (int i = 0; i < resIds.length; i++) { ImageView image = new ImageView(this); image.setImageResource(resIds[i]); image.setId(resIds[i]); image.setOnClickListener(onRightImagesClickListener); rightLl.addView(image, params); } }
public EditDialog(Context context, String title, String value, OnDataSetListener callback) { super(context); mCallback = callback; TextView label = new TextView(context); label.setText("hint"); edit = new EditText(context); edit.setText(value); edit.setPadding(30, 0, 0, 0); layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams param2 = new LinearLayout.LayoutParams(200, 50); param2.leftMargin = 30; layout.addView(edit, param2); setView(layout); setTitle(title); setButton(context.getText(R.string.btn_ok), this); setButton2(context.getText(R.string.btn_cancle), (OnClickListener) null); }
private void initialSetImageIndicators() { indicators = new ImageView[ALBUM_NUM]; for (int i = 0; i < ALBUM_NUM; ++i) { ImageView imageView = new ImageView(this); if (i == 0) { imageView.setImageResource(R.drawable.indicator_select); } else { imageView.setImageResource(R.drawable.indicator_idle); } LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.leftMargin = 5; lp.rightMargin = 5; indicators[i] = imageView; mLinearLayout.addView(imageView, lp); } }
/** 初始化指标器 */ private void initIndication() { mIndicationGroup.removeAllViews(); for (int i = 0; i < mCount; i++) { ImageView imageView = new ImageView(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( mIndicationGroup.getLayoutParams().height, LinearLayout.LayoutParams.MATCH_PARENT); params.leftMargin = (int) (mIndicationGroup.getLayoutParams().height * indication_self_margin_percent); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setLayoutParams(params); if (i == 0) { imageView.setImageBitmap(focusIndicationStyle); } else { imageView.setImageBitmap(unFocusIndicationStyle); } mIndicationGroup.addView(imageView); } }
/** * 把下面的那个点放进viewgroup里 * * @param */ private void putTipsToViewGroup(ViewGroup group, ImageView[] tips) { Log.e("tips", "++++++++++++++++++++++++" + tips.length); for (int i = 0; i < tips.length; i++) { ImageView imageView = new ImageView(this); imageView.setLayoutParams(new LinearLayout.LayoutParams(10, 10)); tips[i] = imageView; if (i == 0) { tips[i].setBackgroundResource(R.drawable.sy_qhs); } else { tips[i].setBackgroundResource(R.drawable.sy_qhk); } LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); layoutParams.leftMargin = 5; layoutParams.rightMargin = 5; group.addView(imageView, layoutParams); } }
/** 加载数据 */ private void setMess() { adaper = new TypeAdaper(); LinearLayout.LayoutParams paramsone = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0); paramsone.topMargin = UtilPixelTransfrom.px2dip(activity, 20); LinearLayout.LayoutParams tempLayoutParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1); tempLayoutParams.rightMargin = UtilPixelTransfrom.px2dip(activity, 4); LinearLayout.LayoutParams paramstwo = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1); paramstwo.leftMargin = UtilPixelTransfrom.px2dip(activity, 4); for (int i = 0; i < 18 / 2; i++) { LinearLayout tempLayouttwo = new LinearLayout(activity); tempLayouttwo.setOrientation(LinearLayout.HORIZONTAL); tempLayouttwo.addView(adaper.getView(i * 2, null, null), tempLayoutParams); tempLayouttwo.addView(adaper.getView(i * 2 + 1, null, null), paramstwo); type_layout.addView(tempLayouttwo, paramsone); } }
private void initView() { goback = (ImageButton) findViewById(R.id.goback); btn_submit = (Button) findViewById(R.id.btn_submit); scroll_page_main = (ScrollView) findViewById(R.id.scroll_page_main); scroll_page_sub = (ScrollView) findViewById(R.id.scroll_page_sub); linear_main = (LinearLayout) findViewById(R.id.linear_main); linear_sub = (LinearLayout) findViewById(R.id.linear_sub); scroll_page_main.setVisibility(View.VISIBLE); scroll_page_sub.setVisibility(View.GONE); params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.height = 1; params.leftMargin = 40; goback.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub finish(); } }); btn_submit.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub code = ""; value = "不限"; Intent intent = new Intent(); intent.putExtra(POSITION_CODES, code); intent.putExtra(POSITION_VALUES, value); ((Activity) context).setResult(SubscribeActivity.REQUESTCODE_POSITIONCLASS, intent); finish(); } }); }
@Override public void initBusiness() { type = (String) getVo("0"); startBaiduLocation(); int width = (AppUtils.getWidth(activity) - 80) / 3; View view = makeView(R.layout.item_photo); ImageView iv_image = (ImageView) view.findViewById(R.id.iv_image); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, width); lp.leftMargin = 18; view.setLayoutParams(lp); iv_image.setImageResource(R.drawable.icon_addzhaopian); view.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { GalleryConfig.Builder builder = new GalleryConfig.Builder(activity); builder.imageloader(new GlideImageLoader()); builder.singleSelect(); builder.enableEdit(); builder.enableRotate(); builder.showCamera(); GalleryConfig config = builder.build(); GalleryFinal.open(config); } }); fl_pics.addView(view); if ("0".equals(type)) { tv_label.setTag(R.id.tag_first, "1"); rl_label.setVisibility(View.GONE); } else if ("1".equals(type)) { tv_label.setTag(R.id.tag_first, "3"); rl_label.setVisibility(View.GONE); tb_notify.setChecked(false); } else { rl_time.setVisibility(View.GONE); } }
public ProcessWatcher(Context context, AttributeSet attrs) { super(context, attrs); final float dp = getResources().getDisplayMetrics().density; mText = new TextView(getContext()); mText.setTextColor(TEXT_COLOR); mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, 10 * dp); mText.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); final int p = (int) (2 * dp); setPadding(p, 0, p, 0); mRamGraph = new GraphView(getContext()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, (int) (14 * dp), 1f); addView(mText, params); params.leftMargin = (int) (4 * dp); params.weight = 0f; params.width = (int) (200 * dp); addView(mRamGraph, params); }
private void Init_Point() { layout_point = (LinearLayout) findViewById(R.id.iv_image); pointViews = new ArrayList<ImageView>(); ImageView imageView; System.out.println(views.size() + "init_point"); for (int i = 0; i < views.size(); i++) { imageView = new ImageView(this); imageView.setBackgroundResource(R.drawable.d1); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); layoutParams.leftMargin = 10; layoutParams.rightMargin = 10; layoutParams.width = 8; layoutParams.height = 8; layout_point.addView(imageView, layoutParams); if (i == 0) { imageView.setBackgroundResource(R.drawable.d2); } else { imageView.setBackgroundResource(R.drawable.d1); } pointViews.add(imageView); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 去掉标题, 必须在setContentView之前执行 requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_guide); mViewPager = (ViewPager) findViewById(R.id.vp_pager); llContainer = (LinearLayout) findViewById(R.id.ll_container); ivRedPoint = (ImageView) findViewById(R.id.iv_red_point); btnStart = (Button) findViewById(R.id.btn_start); btnStart.setOnClickListener(this); // 初始化ImageView mImageViewList = new ArrayList<ImageView>(); for (int i = 0; i < mImageIds.length; i++) { ImageView view = new ImageView(this); view.setBackgroundResource(mImageIds[i]); mImageViewList.add(view); // 初始化圆点 ImageView pointView = new ImageView(this); pointView.setImageResource(R.drawable.shape_circle_default); // 初始化圆点布局参数 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); if (i > 0) { params.leftMargin = DensityUtils.dp2px(8, this); // 从第二个点开始设置边距 } pointView.setLayoutParams(params); llContainer.addView(pointView); } mViewPager.setAdapter(new MyAdapter()); // 页面绘制结束之后, 计算两个圆点的间距 // 视图树 ivRedPoint .getViewTreeObserver() .addOnGlobalLayoutListener( new OnGlobalLayoutListener() { // layout方法执行结束(位置确定) @Override public void onGlobalLayout() { // 移除监听 ivRedPoint.getViewTreeObserver().removeGlobalOnLayoutListener(this); // 获取两个圆点的间距 mPointWidth = llContainer.getChildAt(1).getLeft() - llContainer.getChildAt(0).getLeft(); // System.out.println("width:" + mPointWidth); } }); mViewPager.setOnPageChangeListener( new OnPageChangeListener() { @Override public void onPageSelected(int position) { if (position == mImageIds.length - 1) { // 最后页面显示开始体验 btnStart.setVisibility(View.VISIBLE); } else { btnStart.setVisibility(View.GONE); } } // 页面滑动过程的回调 @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { // System.out.println("当前位置:" + position + ";偏移百分比:" + positionOffset); // 计算当前小红点的左边距 int leftMargin = (int) (mPointWidth * positionOffset + position * mPointWidth); // 修改小红点的左边距 RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ivRedPoint.getLayoutParams(); params.leftMargin = leftMargin; ivRedPoint.setLayoutParams(params); } @Override public void onPageScrollStateChanged(int state) {} }); }
public LcSearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.lc_search_view, this, true); mSearchTrack = findViewById(R.id.lc_search_plate); mTitleIcon = (ImageView) findViewById(R.id.lc_search_icon); mEditorTextView = (SearchAutoComplete) findViewById(R.id.lc_search_src_text); mClearBtn = (ImageView) findViewById(R.id.lc_search_clear_btn); mCancelTextView = (TextView) findViewById(R.id.lc_search_text_cancel); mTitleIcon.setOnClickListener(mOnClickListener); mClearBtn.setOnClickListener(mOnClickListener); mCancelTextView.setOnClickListener(mOnClickListener); mEditorTextView.setOnClickListener(mOnClickListener); mEditorTextView.setOnEditorActionListener(mOnEditorActionListener); mEditorTextView.setOnItemClickListener(mOnItemClickListener); mEditorTextView.addTextChangedListener(mTextWatcher); mEditorTextView.setSearchView(this); mEditorTextView.ensureImeVisible(true); // Inform any listener of focus changes mEditorTextView.setOnFocusChangeListener( new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { mTitleIcon.setAlpha(unfocusAlpha); mEditorTextView.setAlpha(unfocusAlpha); } else { mTitleIcon.setAlpha(1.0f); mEditorTextView.setAlpha(1.0f); } if (mOnTextFocusChangeListener != null) { mOnTextFocusChangeListener.onFocusChange(LcSearchView.this, hasFocus); } } }); mDropDownAnchor = findViewById(mEditorTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { mDropDownAnchor.addOnLayoutChangeListener( new OnLayoutChangeListener() { @Override public void onLayoutChange( View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { adjustDropDownSizeAndPosition(); } }); } int maxWidth = -1; CharSequence cancelText = null; CharSequence queryHintText = null; int clearBtnResId = R.drawable.lc_icon_search_view_clear_light; int titleIconId = R.drawable.lc_icon_search_view_search_light; int searchBgId = R.drawable.lc_selector_search_view_frame_light; int imeOptions = -1; int inputType = -1; boolean focusable = true; final Resources res = getResources(); TypedValue out = new TypedValue(); res.getValue(R.dimen.lc_search_view_default_text_alpha, out, true); unfocusAlpha = out.getFloat(); int queryTextSize = res.getDimensionPixelSize(R.dimen.lc_default_search_query_text_size); ColorStateList queryTextColor = res.getColorStateList(R.color.lc_search_view_query_text_color_light); ColorStateList queryHintTextColor = res.getColorStateList(R.color.lc_search_view_query_hint_text_color_light); int cancelTextSize = res.getDimensionPixelSize(R.dimen.lc_default_search_query_text_size); ColorStateList cancelTextColor = null; int mTrackMarginLeft = res.getDimensionPixelSize(R.dimen.lc_search_track_margin_left); mTrackMarginRight = res.getDimensionPixelSize(R.dimen.lc_search_track_margin_right); int mTrackMarginTop = res.getDimensionPixelSize(R.dimen.lc_search_track_margin_top); int mTrackMarginBottom = res.getDimensionPixelSize(R.dimen.lc_search_track_margin_bottom); int mTrackPaddingLeft = res.getDimensionPixelSize(R.dimen.lc_search_track_padding_left); int mTrackPaddingRight = res.getDimensionPixelSize(R.dimen.lc_search_track_padding_right); mMatchColor = res.getColor(R.color.lc_search_view_drop_down_match_text_color_light); mCursorResId = R.drawable.lc_shape_search_view_cursor_light; mDropDownBg = res.getDrawable(R.drawable.lc_search_drop_down_bg); mDropDownBlurRadius = 10; mPopupItemLayoutResId = R.layout.lc_search_dropdown_item_icons_2line_light; mAlwaysShowCancel = true; Drawable popupDivider = res.getDrawable(R.drawable.lc_search_drop_down_divider); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LcSearchView, defStyleAttr, defStyleRes); a.getValue(R.styleable.LcSearchView_lcSearchUnfocusAlpha, out); unfocusAlpha = out.getFloat(); queryTextSize = a.getDimensionPixelSize(R.styleable.LcSearchView_lcQueryTextSize, queryTextSize); cancelTextSize = a.getDimensionPixelSize(R.styleable.LcSearchView_lcCancelTextSize, cancelTextSize); if (a.hasValue(R.styleable.LcSearchView_lcQueryTextColor)) { queryTextColor = a.getColorStateList(R.styleable.LcSearchView_lcQueryTextColor); } if (a.hasValue(R.styleable.LcSearchView_lcQueryHintColor)) { queryHintTextColor = a.getColorStateList(R.styleable.LcSearchView_lcQueryHintColor); } if (a.hasValue(R.styleable.LcSearchView_lcCancelTextColor)) { cancelTextColor = a.getColorStateList(R.styleable.LcSearchView_lcCancelTextColor); } else { cancelTextColor = queryTextColor; } mTrackMarginBottom = a.getDimensionPixelSize(R.styleable.LcSearchView_lcInputMarginBottom, mTrackMarginBottom); mTrackMarginLeft = a.getDimensionPixelSize(R.styleable.LcSearchView_lcInputMarginLeft, mTrackMarginLeft); mTrackMarginRight = a.getDimensionPixelSize(R.styleable.LcSearchView_lcInputMarginRight, mTrackMarginRight); mTrackMarginTop = a.getDimensionPixelSize(R.styleable.LcSearchView_lcInputMarginTop, mTrackMarginTop); maxWidth = a.getDimensionPixelSize(R.styleable.LcSearchView_android_maxWidth, maxWidth); queryHintText = a.getText(R.styleable.LcSearchView_lcQueryHint); clearBtnResId = a.getResourceId(R.styleable.LcSearchView_lcClearIcon, clearBtnResId); titleIconId = a.getResourceId(R.styleable.LcSearchView_lcSearchIcon, titleIconId); searchBgId = a.getResourceId(R.styleable.LcSearchView_lcBackground, searchBgId); imeOptions = a.getInt(R.styleable.LcSearchView_android_imeOptions, imeOptions); inputType = a.getInt(R.styleable.LcSearchView_android_inputType, inputType); focusable = a.getBoolean(R.styleable.LcSearchView_android_focusable, focusable); mMatchColor = a.getColor(R.styleable.LcSearchView_lcMatchColor, mMatchColor); mCursorResId = a.getResourceId(R.styleable.LcSearchView_android_textCursorDrawable, mCursorResId); if (a.hasValue(R.styleable.LcSearchView_lcCancelText)) { cancelText = a.getString(R.styleable.LcSearchView_lcCancelText); } if (a.hasValue(R.styleable.LcSearchView_lcPopupBackground)) { mDropDownBg = a.getDrawable(R.styleable.LcSearchView_lcPopupBackground); } if (a.hasValue(R.styleable.LcSearchView_lcPopupListDivider)) { popupDivider = a.getDrawable(R.styleable.LcSearchView_lcPopupListDivider); } mDropDownBlurRadius = a.getDimensionPixelSize(R.styleable.LcSearchView_lcPopupBlurRadius, mDropDownBlurRadius); mPopupItemLayoutResId = a.getResourceId(R.styleable.LcSearchView_lcPopupItemLayout, mPopupItemLayoutResId); final int completeThreshold = a.getInt(R.styleable.LcSearchView_android_completionThreshold, 2); mAlwaysShowCancel = a.getBoolean(R.styleable.LcSearchView_lcAlwaysShowCancel, mAlwaysShowCancel); a.recycle(); mEditorTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, queryTextSize); mEditorTextView.setTextColor(queryTextColor); mEditorTextView.setHintTextColor(queryHintTextColor); HIDDEN_METHOD.setCursorDrawableRes(mEditorTextView, mCursorResId); mEditorTextView.setPopupBackground(mDropDownBg); mEditorTextView.setPopupListDivider(popupDivider); mEditorTextView.setPopupBlurRadius(mDropDownBlurRadius); mEditorTextView.setThreshold(completeThreshold); if (mEditorTextView.hasFocus()) { mTitleIcon.setAlpha(1.0f); mEditorTextView.setAlpha(1.0f); } else { mTitleIcon.setAlpha(unfocusAlpha); mEditorTextView.setAlpha(unfocusAlpha); } mCancelTextView.setTextColor(cancelTextColor); mCancelTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, cancelTextSize); if (mAlwaysShowCancel) { mCancelTextView.setVisibility(View.VISIBLE); } mClearBtn.setImageResource(clearBtnResId); mTitleIcon.setImageResource(titleIconId); mSearchTrack.setBackgroundResource(searchBgId); LinearLayout.LayoutParams plateParams = (LinearLayout.LayoutParams) mSearchTrack.getLayoutParams(); plateParams.topMargin = mTrackMarginTop; plateParams.bottomMargin = mTrackMarginBottom; plateParams.leftMargin = mTrackMarginLeft; plateParams.rightMargin = mAlwaysShowCancel ? 0 : mTrackMarginRight; LinearLayout.LayoutParams params = (LayoutParams) mTitleIcon.getLayoutParams(); params.leftMargin = mTrackPaddingLeft; params = (LayoutParams) mClearBtn.getLayoutParams(); params.rightMargin = mTrackPaddingRight; mCancelTextView.setPadding(mTrackMarginRight, 0, mTrackMarginRight, 0); if (maxWidth != -1) { setMaxWidth(maxWidth); } if (!TextUtils.isEmpty(queryHintText)) { setQueryHint(queryHintText); } if (imeOptions != -1) { setImeOptions(imeOptions); } if (inputType != -1) { setInputType(inputType); } if (cancelText != null) { mCancelTextView.setText(cancelText); } setFocusable(focusable); updateQueryHint(); }
private static void init() { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); _root = new LinearLayout(_context); _root.setOrientation(LinearLayout.VERTICAL); _root.setLayoutParams(params); // Button Area params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout button_layout = new LinearLayout(_context); button_layout.setOrientation(LinearLayout.VERTICAL); button_layout.setLayoutParams(params); MomoImageButton btn_capture_image = new MomoImageButton(_context); MomoImageButton btn_record_video = new MomoImageButton(_context); MomoImageButton btn_record_audio = new MomoImageButton(_context); MomoImageButton btn_load_image = new MomoImageButton(_context); MomoImageButton btn_load_video = new MomoImageButton(_context); MomoImageButton btn_load_audio = new MomoImageButton(_context); params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); params.weight = 1; params.leftMargin = 10; params.rightMargin = 10; params.topMargin = 20; btn_capture_image.setIcon(R.drawable.camera); btn_record_video.setIcon(R.drawable.vedio_recorder); btn_record_audio.setIcon(R.drawable.audio_recorder); btn_load_image.setIcon(R.drawable.import_image); btn_load_video.setIcon(R.drawable.import_video); btn_load_audio.setIcon(R.drawable.import_audio); btn_capture_image.setTextSize(18); btn_record_video.setTextSize(18); btn_record_audio.setTextSize(18); btn_load_image.setTextSize(18); btn_load_video.setTextSize(18); btn_load_audio.setTextSize(18); btn_capture_image.setText(_context.getString(R.string.text_take_photo)); btn_record_video.setText(_context.getString(R.string.text_record_video)); btn_record_audio.setText(_context.getString(R.string.text_record_audio)); btn_load_image.setText(_context.getString(R.string.text_import_image)); btn_load_video.setText(_context.getString(R.string.text_import_video)); btn_load_audio.setText(_context.getString(R.string.text_import_audio)); btn_capture_image.setLayoutParams(params); btn_load_image.setLayoutParams(params); btn_record_audio.setLayoutParams(params); btn_record_video.setLayoutParams(params); btn_load_video.setLayoutParams(params); btn_load_audio.setLayoutParams(params); btn_load_audio.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { _listener.onImportAudio(); } }); btn_record_audio.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { _listener.onRecordAudio(); } }); btn_capture_image.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { _listener.onTakePhoto(); } }); btn_load_image.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { _listener.onImportImage(); } }); btn_record_video.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { _listener.onRecordvideo(); } }); btn_load_video.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { _listener.onImportVideo(); } }); button_layout.addView(btn_capture_image); button_layout.addView(btn_record_video); button_layout.addView(btn_record_audio); button_layout.addView(btn_load_image); button_layout.addView(btn_load_video); button_layout.addView(btn_load_audio); _root.addView(button_layout); }
protected void onCreateContent(LinearLayout parent) { SizeHelper.prepare(context); LinearLayout rlCountry = new LinearLayout(context); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, SizeHelper.fromPxWidth(96)); params.setMargins( SizeHelper.fromPx(26), SizeHelper.fromPxWidth(32), SizeHelper.fromPxWidth(26), 0); rlCountry.setLayoutParams(params); rlCountry.setId(Res.id.rl_country); TextView tv = new TextView(context); LinearLayout.LayoutParams tvParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tvParams.gravity = Gravity.CENTER_VERTICAL; tv.setLayoutParams(tvParams); tv.setPadding(SizeHelper.fromPxWidth(14), 0, SizeHelper.fromPxWidth(14), 0); int resid = R.getStringRes(context, "smssdk_country"); tv.setText(resid); tv.setTextColor(0xff000000); tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); rlCountry.addView(tv); TextView tvCountry = new TextView(context); tvCountry.setId(Res.id.tv_country); LinearLayout.LayoutParams tvCountryParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tvCountryParams.gravity = Gravity.CENTER_VERTICAL; tvCountryParams.weight = 1; tvCountryParams.rightMargin = SizeHelper.fromPxWidth(14); tvCountry.setLayoutParams(tvCountryParams); tvCountry.setGravity(Gravity.RIGHT); tvCountry.setPadding(SizeHelper.fromPxWidth(14), 0, SizeHelper.fromPxWidth(14), 0); tvCountry.setTextColor(0xff45c01a); tvCountry.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); rlCountry.addView(tvCountry); parent.addView(rlCountry); View line = new View(context); LinearLayout.LayoutParams lineParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, SizeHelper.fromPxWidth(1)); lineParams.leftMargin = SizeHelper.fromPxWidth(26); lineParams.rightMargin = SizeHelper.fromPxWidth(26); line.setLayoutParams(lineParams); line.setBackgroundColor(Res.color.smssdk_gray_press); parent.addView(line); LinearLayout phoneLayout = new LinearLayout(context); LinearLayout.LayoutParams phoneParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, SizeHelper.fromPxWidth(70)); phoneParams.setMargins( SizeHelper.fromPxWidth(26), SizeHelper.fromPxWidth(30), SizeHelper.fromPxWidth(26), 0); phoneLayout.setLayoutParams(phoneParams); TextView countryNum = new TextView(context); countryNum.setId(Res.id.tv_country_num); LinearLayout.LayoutParams countryNumParams = new LinearLayout.LayoutParams( SizeHelper.fromPxWidth(104), LinearLayout.LayoutParams.MATCH_PARENT); countryNum.setLayoutParams(countryNumParams); countryNum.setGravity(Gravity.CENTER); countryNum.setTextColor(0xff353535); countryNum.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); resid = R.getBitmapRes(context, "smssdk_input_bg_focus"); countryNum.setBackgroundResource(resid); phoneLayout.addView(countryNum); LinearLayout wrapperLayout = new LinearLayout(context); LinearLayout.LayoutParams wrapperParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT); wrapperParams.weight = 1; wrapperLayout.setLayoutParams(wrapperParams); resid = R.getBitmapRes(context, "smssdk_input_bg_special_focus"); wrapperLayout.setBackgroundResource(resid); EditText writePhone = new EditText(context); writePhone.setId(Res.id.et_write_phone); LinearLayout.LayoutParams writePhoneParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT); writePhoneParams.gravity = Gravity.CENTER_VERTICAL; writePhoneParams.setMargins(SizeHelper.fromPxWidth(10), 0, SizeHelper.fromPxWidth(10), 0); writePhoneParams.weight = 1; writePhone.setLayoutParams(writePhoneParams); writePhone.setBackgroundDrawable(null); resid = R.getStringRes(context, "smssdk_write_mobile_phone"); writePhone.setHint(resid); writePhone.setInputType(InputType.TYPE_CLASS_PHONE); writePhone.setTextColor(0xff353535); writePhone.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); wrapperLayout.addView(writePhone); ImageView image = new ImageView(context); image.setId(Res.id.iv_clear); LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams(SizeHelper.fromPxWidth(24), SizeHelper.fromPxWidth(24)); imageParams.gravity = Gravity.CENTER_VERTICAL; imageParams.rightMargin = SizeHelper.fromPxWidth(20); image.setLayoutParams(imageParams); resid = R.getBitmapRes(context, "smssdk_clear_search"); image.setBackgroundResource(resid); image.setScaleType(ScaleType.CENTER_INSIDE); image.setVisibility(View.GONE); wrapperLayout.addView(image); phoneLayout.addView(wrapperLayout); parent.addView(phoneLayout); Button nextBtn = new Button(context); nextBtn.setId(Res.id.btn_next); LinearLayout.LayoutParams nextParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, SizeHelper.fromPxWidth(72)); nextParams.setMargins( SizeHelper.fromPxWidth(26), SizeHelper.fromPxWidth(36), SizeHelper.fromPxWidth(26), 0); nextBtn.setLayoutParams(nextParams); resid = R.getBitmapRes(context, "smssdk_btn_disenable"); nextBtn.setBackgroundResource(resid); resid = R.getStringRes(context, "smssdk_next"); nextBtn.setText(resid); nextBtn.setTextColor(0xffffffff); nextBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(25)); nextBtn.setPadding(0, 0, 0, 0); parent.addView(nextBtn); }