public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; if (row == null) { LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(layoutId, parent, false); } messageContainer = (LinearLayout) row.findViewById(R.id.singleMessageContainer); PikachuMessage message = getItem(position); String messageStr = message.getMsg(); singleMessage = (TextView) row.findViewById(R.id.singleMessage); processMessage(message.getMsg()); // singleMessage.setText(messageStr); if (message .getUser() .getUsername() .equals(((MyApplication) context.getApplication()).user.getUsername())) { singleMessage.setBackgroundResource(R.drawable.bubble_a); messageContainer.setGravity(Gravity.RIGHT); } else { singleMessage.setBackgroundResource(R.drawable.bubble_b); messageContainer.setGravity(Gravity.LEFT); } return row; }
private void init() { // TODO Auto-generated method stub // 线性布局 LinearLayout layout = new LinearLayout(this); // 设置布局 水平方向 layout.setOrientation(LinearLayout.HORIZONTAL); // 进度条 progressBar = new ProgressBar(this); // 进度条显示位置 progressBar.setPadding(0, 0, 15, 0); // 把进度条加入到layout中 layout.addView(progressBar, mLayoutParams); // 文本内容 TextView textView = new TextView(this); textView.setText("加载中..."); textView.setGravity(Gravity.CENTER_VERTICAL); // 把文本加入到layout中 layout.addView(textView, FFlayoutParams); // 设置layout的重力方向,即对齐方式是 layout.setGravity(Gravity.CENTER); // 设置ListView的页脚layout loadingLayout = new LinearLayout(this); loadingLayout.addView(layout, mLayoutParams); loadingLayout.setGravity(Gravity.CENTER); // 得到一个ListView用来显示条目 listView = (ListView) findViewById(R.id.tv); // 添加到脚页显示 listView.addFooterView(loadingLayout); // 给ListView添加适配器 listView.setAdapter(adapter); // 给ListView注册滚动监听 listView.setOnScrollListener(this); }
/** * * * * @return */ private LinearLayout getTitleView(String title, int id) { LinearLayout linearLayout = new LinearLayout(getApplicationContext()); linearLayout.setPadding(5, 5, 5, 5); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, Utils.convertDips2Pixel(45, getApplicationContext()))); linearLayout.setBackgroundResource(R.drawable.title_bar); LinearLayout.LayoutParams layoutParamsColumn = new LinearLayout.LayoutParams( TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT, 1); LinearLayout linearLayoutLeft = new LinearLayout(getApplicationContext()); linearLayoutLeft.setGravity(Gravity.LEFT | Gravity.CENTER); linearLayoutLeft.setLayoutParams(layoutParamsColumn); JTextView jTextViewTitleControl = new JTextView(getApplicationContext()); jTextViewTitleControl.setTextColor(0xFF000000); jTextViewTitleControl.setModeSubTitle(getApplicationContext()); jTextViewTitleControl.setGravity(Gravity.CENTER); jTextViewTitleControl.setText(title); linearLayoutLeft.addView(jTextViewTitleControl); linearLayout.addView(linearLayoutLeft); LinearLayout linearLayoutRight = new LinearLayout(getApplicationContext()); linearLayoutRight.setGravity(Gravity.RIGHT | Gravity.CENTER); linearLayoutRight.setLayoutParams(layoutParamsColumn); ImageView imageView = new ImageView(getApplicationContext()); imageView.setImageResource(id); linearLayoutRight.addView(imageView); linearLayout.addView(linearLayoutRight); return linearLayout; }
protected void b() { c = new je(this, a); b = new WindowManager.LayoutParams(); b.width = -1; b.height = -1; b.format = -2; c.setVisibility(8); c.setBackgroundDrawable(null); c.setOnClickListener(new jf(this)); if (e) { g = new jg(this, a, h); c.setGravity(53); LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams(-2, -2); if ((a instanceof jb)) { Rect localRect1 = ((jb) a).t(); if (localRect1 != null) { Rect localRect2 = new Rect(); ((Activity) a).getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect2); int k = top; height = localRect1.height(); topMargin = (top - k); } } c.addView(g.a(), localLayoutParams); return; } g = new jh(this, a, h); c.setGravity(17); c.addView(g.a()); }
/** * getChildView * * @param int group_position * @param int child_position * @param boolean is_last_child * @param View convert_view * @param ViewGroup parent * @return View */ public View getChildView( int group_position, int child_position, boolean is_last_child, View convert_view, ViewGroup parent) { // get the current setting ServiceSetting setting = (ServiceSetting) getChild(group_position, child_position); // create a text layout AbsListView.LayoutParams text_layout_params = new AbsListView.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout text_layout = new LinearLayout(activity); TextView text_view = getGenericView(); text_view.setText(setting.getDisplayName()); text_view.setTextColor(Color.BLACK); text_layout.setLayoutParams(text_layout_params); text_layout.setOrientation(LinearLayout.HORIZONTAL); text_layout.addView(text_view); // create checkbox CheckBox check_box = new CheckBox(activity); check_box.setChecked(setting.getPrefValue()); check_box.setOnClickListener(setting); // create a check box layout AbsListView.LayoutParams check_box_layout_params = new AbsListView.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout check_box_layout = new LinearLayout(activity); check_box_layout.setLayoutParams(check_box_layout_params); check_box_layout.setGravity(Gravity.RIGHT); check_box_layout.setPadding(0, 0, 5, 0); check_box_layout.addView(check_box); // create row and add text and check box layouts to it AbsListView.LayoutParams main_layout_params = new AbsListView.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); LinearLayout main_layout = new LinearLayout(activity); // add to main layout main_layout.setLayoutParams(main_layout_params); main_layout.setOrientation(LinearLayout.HORIZONTAL); main_layout.addView(text_layout); main_layout.setGravity(Gravity.CENTER); main_layout.addView(check_box_layout); return main_layout; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layoutMain = new LinearLayout(this); layoutMain.setOrientation(LinearLayout.VERTICAL); layoutMain.setBackgroundColor(Color.CYAN); LinearLayout layoutTitle = new LinearLayout(this); layoutTitle.setOrientation(LinearLayout.VERTICAL); layoutTitle.setGravity(Gravity.TOP); layoutMain.addView(layoutTitle); TextView heading = new TextView(this); heading.setText("DETECTING INPUT EVENTS \n (Click Or Long Press)"); heading.setHeight(100); heading.setGravity(Gravity.TOP | Gravity.CENTER); heading.setBackgroundColor(Color.YELLOW); heading.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25); heading.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); layoutTitle.addView(heading); LinearLayout layoutBody = new LinearLayout(this); layoutBody.setOrientation(LinearLayout.VERTICAL); layoutBody.setGravity(Gravity.CENTER_HORIZONTAL); layoutMain.addView(layoutBody); Button btn1 = new Button(this); btn1.setWidth(10); btn1.setGravity(Gravity.CENTER); btn1.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25); btn1.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); btn1.setText("Click Me With Any Style"); layoutBody.addView(btn1); btn1.setOnClickListener(this); btn1.setOnLongClickListener( new View.OnLongClickListener() { public boolean onLongClick(View v) { result.setText("You long pressed the button !!"); return true; } }); result = new TextView(this); result.setHeight(200); result.setGravity(Gravity.CENTER); result.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); result.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); layoutBody.addView(result); setContentView(layoutMain); }
public LinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); this.mBaselineAligned = true; this.mBaselineAlignedChildIndex = -1; this.mBaselineChildTop = SHOW_DIVIDER_NONE; this.mGravity = 8388659; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinearLayout, defStyleAttr, defStyleRes); int index = a.getInt(VERTICAL, -1); if (index >= 0) { setOrientation(index); } index = a.getInt(SHOW_DIVIDER_NONE, -1); if (index >= 0) { setGravity(index); } boolean baselineAligned = a.getBoolean(SHOW_DIVIDER_MIDDLE, true); if (!baselineAligned) { setBaselineAligned(baselineAligned); } this.mWeightSum = a.getFloat( VERTICAL_GRAVITY_COUNT, android.view.WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE); this.mBaselineAlignedChildIndex = a.getInt(INDEX_FILL, -1); this.mUseLargestChild = a.getBoolean(6, false); setDividerDrawable(a.getDrawable(5)); this.mShowDividers = a.getInt(7, SHOW_DIVIDER_NONE); this.mDividerPadding = a.getDimensionPixelSize(8, SHOW_DIVIDER_NONE); a.recycle(); }
private void init(Context context, AttributeSet attrs) { if (attrs == null) { return; } TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ImageTextButton); mIconPositon = typedArray.getInt(R.styleable.ImageTextButton_itb_icon_position, ICON_POSITION_LEFT); View rootView = initLayout(context); mArea = getArea(rootView); mIconView = getIconView(mArea); mBtnTextView = getBtnTextView(mArea); if (mArea == null || mIconView == null || mBtnTextView == null) { return; } mArea.setGravity(CENTER_IN_PARENT); // padding initPadding(typedArray); // backgroud shap initBackground(typedArray); // button text initTextView(typedArray, mBtnTextView); // icon initIcon(typedArray, mIconView); typedArray.recycle(); }
@Override @NonNull protected LinearLayout makeCenterView() { LinearLayout rootLayout = new LinearLayout(activity); rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); rootLayout.setOrientation(LinearLayout.VERTICAL); blackColorView = new ColorPanelView(activity); //noinspection ResourceType blackColorView.setId(BLACK_ID); blackColorView.setLayoutParams( new LinearLayout.LayoutParams(MATCH_PARENT, ConvertUtils.toPx(activity, 30))); blackColorView.setPointerDrawable( CompatUtils.getDrawable(activity, R.drawable.color_picker_cursor_bottom)); blackColorView.setLockPointerInBounds(false); blackColorView.setOnColorChangedListener( new ColorPanelView.OnColorChangedListener() { @Override public void onColorChanged(ColorPanelView view, int color) { updateCurrentColor(color); } }); rootLayout.addView(blackColorView); multiColorView = new ColorPanelView(activity); //noinspection ResourceType multiColorView.setId(MULTI_ID); multiColorView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f)); multiColorView.setPointerDrawable( CompatUtils.getDrawable(activity, R.drawable.color_picker_cursor_top)); multiColorView.setLockPointerInBounds(true); multiColorView.setOnColorChangedListener( new ColorPanelView.OnColorChangedListener() { @Override public void onColorChanged(ColorPanelView view, int color) { updateCurrentColor(color); } }); rootLayout.addView(multiColorView); LinearLayout previewLayout = new LinearLayout(activity); previewLayout.setOrientation(LinearLayout.HORIZONTAL); previewLayout.setGravity(Gravity.CENTER); previewLayout.setLayoutParams( new LinearLayout.LayoutParams(MATCH_PARENT, ConvertUtils.toPx(activity, 30))); hexValView = new EditText(activity); hexValView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); hexValView.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); hexValView.setImeOptions(EditorInfo.IME_ACTION_DONE); hexValView.setGravity(Gravity.CENTER); hexValView.setBackgroundColor(initColor); hexValView.setTextColor(Color.BLACK); hexValView.setShadowLayer(3, 0, 2, Color.WHITE); // 设置阴影,以便背景色为黑色系列时仍然看得见 hexValView.setMinEms(6); hexValView.setMaxEms(8); hexValView.setPadding(0, 0, 0, 0); hexValView.setSingleLine(true); hexValView.setOnEditorActionListener(this); hexValDefaultColor = hexValView.getTextColors(); previewLayout.addView(hexValView); rootLayout.addView(previewLayout); return rootLayout; }
public static void makeText(Context context, String text, int duration) { getInstance(context); getToast(duration); if (mInstance.layout == null || mInstance.tv == null) { LinearLayout container = new LinearLayout(mContext); LinearLayout.LayoutParams rootParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); container.setLayoutParams(rootParams); container.setBackgroundColor(context.getResources().getColor(android.R.color.transparent)); container.setGravity(Gravity.CENTER); mInstance.tv = new TextView(mContext); LinearLayout.LayoutParams tvParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); mInstance.tv.setLayoutParams(tvParams); mInstance.tv.setPadding(dp2px(10), dp2px(2), dp2px(10), dp2px(2)); mInstance.tv.setGravity(Gravity.CENTER); mInstance.tv.setTextColor(DEFAULT_TEXT_COLOR); mInstance.tv.setMaxLines(2); mInstance.tv.setEllipsize(TextUtils.TruncateAt.END); mInstance.tv.setTextSize(DEFAULT_TEXT_SIZE); mInstance.tv.setBackgroundResource(DEFAULT_BG_TEXT); container.addView(mInstance.tv); mInstance.layout = container; mToast.setView(mInstance.layout); } mInstance.tv.setText(text); mToast.show(); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Find Views mListView = (ListView) findViewById(R.id.listView1); /** 用mLinear做为load-progress的容器。 */ LinearLayout mLinear = new LinearLayout(this); mLinear.setOrientation(LinearLayout.HORIZONTAL); mProgressBar = new ProgressBar(this); mProgressBar.setPadding(0, 0, 15, 0); mLinear.addView(mProgressBar, WClayoutParams); TextView textView = new TextView(this); textView.setText("加载中..."); textView.setGravity(Gravity.CENTER_VERTICAL); mLinear.addView(textView, FFlayoutParams); mLinear.setGravity(Gravity.CENTER); registerForContextMenu(mListView); // 将load-progress加进ListView的最底行 mListView.addFooterView(mLinear); mAdapter = new PageAdapter(); mListView.setAdapter(mAdapter); mListView.setOnScrollListener(this); }
private void loadAttributes(Context context, AttributeSet attrs) { TypedValue outValue = new TypedValue(); Resources.Theme theme = context.getTheme(); // use ?attr/colorPrimary as background color theme.resolveAttribute(R.attr.colorPrimary, outValue, true); TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.FooterLayout, 0, 0); int containerGravity; try { setColor(a.getColor(R.styleable.FooterLayout_ft_color, outValue.data)); startAnimationDuration = a.getInteger( R.styleable.FooterLayout_ft_start_anim_duration, DEFAULT_START_ANIMATION_DURATION); endAnimationDuration = a.getInteger( R.styleable.FooterLayout_ft_end_anim_duration, DEFAULT_END_ANIMATION_DURATION); containerGravity = a.getInteger(R.styleable.FooterLayout_ft_container_gravity, 1); mFabSize = a.getInteger(R.styleable.FooterLayout_ft_fab_type, DEFAULT_FAB_SIZE); } finally { a.recycle(); } mFabExpandLayout.setGravity(getGravity(containerGravity)); }
private void init(MainView v, Object params) { Context ctx = RhodesActivity.getContext(); view = new MyView(ctx); view.setOrientation(LinearLayout.VERTICAL); view.setGravity(Gravity.BOTTOM); view.setLayoutParams(new LinearLayout.LayoutParams(FILL_PARENT, FILL_PARENT)); webView = null; if (v != null) webView = v.detachWebView(); if (webView == null) webView = RhodesActivity.safeGetInstance().createWebView(); view.addView(webView, new LinearLayout.LayoutParams(FILL_PARENT, 0, 1)); LinearLayout bottom = new LinearLayout(ctx); bottom.setOrientation(LinearLayout.HORIZONTAL); bottom.setBackgroundColor(Color.GRAY); bottom.setLayoutParams(new LinearLayout.LayoutParams(FILL_PARENT, WRAP_CONTENT, 0)); view.addView(bottom); toolBar = bottom; setupToolbar(toolBar, params); webView.requestFocus(); }
private void dibujarCheck() { contenido.removeAllViews(); for (Modulo m : modulos) { TextView mTitulo = new TextView(this); mTitulo.setText(m.getName()); mTitulo.setBackgroundColor(Color.parseColor("#226666")); mTitulo.setTextColor(Color.WHITE); mTitulo.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mTitulo.setPadding(0, 6, 0, 6); mTitulo.setGravity(Gravity.CENTER_HORIZONTAL); contenido.addView(mTitulo); LinearLayout itemLayout = new LinearLayout(this); itemLayout.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); itemLayout.setBackgroundResource(R.drawable.fondo_1); itemLayout.setGravity(Gravity.CENTER_HORIZONTAL); itemLayout.setOrientation(LinearLayout.VERTICAL); itemLayout.setPadding(16, 5, 16, 5); for (cl.tdc.felipe.tdc.objects.Relevar.Item item : m.getItems()) { TextView iTitulo = new TextView(this); iTitulo.setText(item.getName()); iTitulo.setBackgroundColor(Color.GREEN); iTitulo.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); iTitulo.setPadding(0, 8, 0, 4); iTitulo.setGravity(Gravity.CENTER_HORIZONTAL); View vista = getView(m.getId(), item); if (vista == null) continue; itemLayout.addView(iTitulo); itemLayout.addView(vista); vistas.add(vista); } contenido.addView(itemLayout); } Button agregarFoto = new Button(this); agregarFoto.setText("Agregar Foto"); agregarFoto.setBackgroundResource(R.drawable.custom_button_rounded_green); agregarFoto.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { imgTmp = new FormImage(); imgTmp.setIdSystem(estaciones.get(station.getSelectedItemPosition()).getId()); tomarFoto(); } }); contenido.addView(agregarFoto); }
/** * add the section tabs for different segment structures. For example in Genesis these can be: * Chapters | Parshas | Commentary * * @param nodeList */ private void addTabsection(List<BilingualNode> nodeList) { tabRoot = new LinearLayout(context); tabRoot.setOrientation(LinearLayout.HORIZONTAL); tabRoot.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); tabRoot.setGravity(Gravity.CENTER); this.addView(tabRoot, 0); // make sure it's on top for (int count = 0; count < nodeList.size(); count++) { MenuNode menuNode = (MenuNode) nodeList.get(count); // although generally this isn't necessary b/c the nodes come from menuState.getSections // this is used when rebuilding after memory dump and nodes come from setHasTabs() if (menuNode.getTitle(Util.Lang.EN).equals("Commentary") || (menuNode.getTitle(Util.Lang.EN).equals("Rif"))) { continue; } if (count > 0 && count < nodeList.size()) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.tab_divider_menu, tabRoot); } MenuButtonTab mbt = new MenuButtonTab(context, menuNode, menuState.getLang()); mbt.setOnClickListener(tabButtonClick); tabRoot.addView(mbt); menuElementList.add(mbt); menuButtonTabList.add(mbt); } }
public static WaitDialog showNormalWithHintProgress(Context mContext, String hint, boolean show) { LinearLayout ll = null; if (show) { ll = new LinearLayout(mContext); ll.setBackgroundColor(Color.TRANSPARENT); ll.setOrientation(LinearLayout.VERTICAL); ImageView iv = new ImageView(mContext); iv.setImageResource(R.drawable.spin_black_70); iv.setPadding(20, 20, 20, 20); ll.addView( iv, new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); ll.setTag(iv); TextView tv = new TextView(mContext); tv.setText(hint); ll.addView( tv, new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); ll.setGravity(Gravity.CENTER); } else ll = null; return showProgress(mContext, show, ll); }
private void createView() { // Linear Layout LinearLayout linearLayout = new LinearLayout(this); linearLayout.setId(1); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setGravity(Gravity.CENTER); linearLayout.setBackgroundColor(Color.BLACK); this.setContentView(linearLayout); // Relative Layout RelativeLayout relativeLayout = new RelativeLayout(this); relativeLayout.setId(2); relativeLayout.setGravity(Gravity.CENTER); relativeLayout.setBackgroundColor(Color.BLACK); RelativeLayout.LayoutParams relativeLayoutParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); relativeLayout.setLayoutParams(relativeLayoutParams); linearLayout.addView(relativeLayout); // Video View videoView = new VideoView(this); videoView.setId(3); RelativeLayout.LayoutParams videoViewParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); videoViewParams.addRule(RelativeLayout.CENTER_IN_PARENT); videoView.setLayoutParams(videoViewParams); relativeLayout.addView(videoView); }
/** * 绘制导航布局 * * @return */ private LinearLayout drawNavTitle() { LinearLayout navTitle = createLinearLayout(LinearLayout.HORIZONTAL, LayoutParams.MATCH_PARENT, 0, 1.5f); navTitle.setGravity(Gravity.CENTER); // 左右按键和中间标题应该很容易看懂 ImageButton left = new ImageButton(getContext()); left.setBackgroundColor(Color.TRANSPARENT); ImageButton right = new ImageButton(getContext()); right.setBackgroundColor(Color.TRANSPARENT); title = new TextView(getContext()); title.setTextSize(getResources().getDimension(R.dimen.calendar_title)); title.setPadding((int) (0.5 * tb), (int) (0.5 * tb), (int) (0.5 * tb), (int) (0.5 * tb)); navTitle.addView(left); navTitle.addView(title); navTitle.addView(right); left.setImageResource(R.drawable.calendar_prev); right.setImageResource(R.drawable.calendar_next); // 点击事件 left.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { lastMonth(); } }); right.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { nextMonth(); } }); return navTitle; }
private LinearLayout getTitleView(Context context, AlertType type) { this.context = context; LinearLayout mainLine = new LinearLayout(context); mainLine.setOrientation(LinearLayout.HORIZONTAL); LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); mainLine.setLayoutParams(layoutParams); mainLine.setPadding( Tool.dip2px(context, 10), Tool.dip2px(context, 10), Tool.dip2px(context, 10), Tool.dip2px(context, 10)); mainLine.setGravity(Gravity.CENTER_VERTICAL); mainLine.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.toast_background)); ImageView imageView = new ImageView(context); if (type == AlertType.ERR) { imageView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.err)); } else if (type == AlertType.INFO) { imageView.setBackgroundDrawable( context.getResources().getDrawable(R.drawable.radio_bt_selected)); } else { imageView.setBackgroundDrawable(null); } mainLine.addView(imageView); textView = new TextView(context); textView.setTextColor(context.getResources().getColor(R.color.white)); textView.setTextSize(16); mainLine.addView(textView); return mainLine; }
// 录音时间太短时Toast显示 void showWarnToast(String toastText) { Toast toast = new Toast(ChatActivity.this); LinearLayout linearLayout = new LinearLayout(ChatActivity.this); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setPadding(20, 20, 20, 20); // 定义一个ImageView ImageView imageView = new ImageView(ChatActivity.this); imageView.setImageResource(R.mipmap.voice_to_short); // 图标 TextView mTv = new TextView(ChatActivity.this); mTv.setText(toastText); mTv.setTextSize(14); mTv.setTextColor(Color.WHITE); // 字体颜色 // 将ImageView和ToastView合并到Layout中 linearLayout.addView(imageView); linearLayout.addView(mTv); linearLayout.setGravity(Gravity.CENTER); // 内容居中 linearLayout.setBackgroundResource(R.mipmap.record_bg); // 设置自定义toast的背景 toast.setView(linearLayout); toast.setGravity(Gravity.CENTER, 0, 0); // 起点位置为中间 toast.show(); }
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { WebView webView = new WebView(getActivity()); // TextView text = new TextView(getActivity()); // text.setGravity(Gravity.CENTER); // text.setText(mContent); // text.setTextSize(13 * getResources().getDisplayMetrics().scaledDensity); // text.setPadding(20, 20, 20, 20); // text.setTextColor(getResources().getColor(R.color.colorFuenteAzul)); webView.getSettings().setDefaultFontSize(19); webView.loadDataWithBaseURL(null, mContent, "text/html", "utf-8", null); LinearLayout layout = new LinearLayout(getActivity()); int px = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics()); layout.setLayoutParams(new LayoutParams(px, LayoutParams.MATCH_PARENT)); layout.setGravity(Gravity.CENTER); layout.addView(webView); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { layout.setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_border)); } else { layout.setBackground(getResources().getDrawable(R.drawable.rounded_border)); } return layout; }
// 动态设置小点 private void initDots() { LinearLayout ll = (LinearLayout) findViewById(R.id.ll); // ll.setOrientation(LinearLayout.HORIZONTAL); ImageView[] image_dot = new ImageView[4]; LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); ll.setGravity(Gravity.CENTER_HORIZONTAL); params.setMargins(10, 10, 10, 10); for (int i = 0; i < 4; i++) { image_dot[i] = new ImageView(this); image_dot[i].setClickable(true); // image_dot[i].setPadding(5, 5, 5, 5); image_dot[i].setLayoutParams(params); image_dot[i].setBackgroundResource(R.drawable.dot); } dots = new ImageView[imageurl.size()]; // 循环取得小点图片 for (int i = 0; i < imageurl.size(); i++) { ll.addView(image_dot[i]); dots[i] = (ImageView) ll.getChildAt(i); dots[i].setEnabled(true); // 都设为黄色 dots[i].setOnClickListener(this); dots[i].setTag(i); // 设置位置tag,方便取出与当前位置对应 } currentIndex = 0; dots[currentIndex].setEnabled(false); // 设置为白色,即选中状态 }
private void updateTabStyles() { // change Tab gravity tabsContainer.setGravity(tabGravity); for (int i = 0; i < tabCount; i++) { View v = tabsContainer.getChildAt(i); v.setBackgroundResource(tabBackgroundResId); if (v instanceof TextView) { TextView tab = (TextView) v; tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab.setTypeface(tabTypeface, tabTypefaceStyle); tab.setTextColor(tabTextColor); // setAllCaps() is only available from API 14, so the upper case // is made manually if we are on a // pre-ICS-build if (textAllCaps) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { tab.setAllCaps(true); } else { tab.setText(tab.getText().toString().toUpperCase(locale)); } } } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); LinearLayout myLayout = new LinearLayout(this); myLayout.setOrientation(LinearLayout.VERTICAL); input1 = new EditText(this); output1 = new TextView(this); button1 = new Button(this); bannerText = new TextView(this); myLayout.setOrientation(LinearLayout.VERTICAL); myLayout.setGravity(Gravity.CENTER_HORIZONTAL); myLayout.setBackgroundColor(Color.LTGRAY); bannerText.setWidth(300); bannerText.setGravity(Gravity.CENTER_HORIZONTAL); bannerText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 50); bannerText.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); bannerText.setText(" Currency Converter from Dollar $ to Birr"); bannerText.setTextColor(Color.BLUE); bannerText.setPadding(0, 0, 0, 10); input1.setHint("Enter Dollar amount"); button1.setText("Convert to Birr!"); output1.setText("0"); output1.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30); output1.setPadding(0, 20, 0, 20); output1.setWidth(150); output1.setGravity(Gravity.CENTER_HORIZONTAL); output1.setTextColor(Color.WHITE); // button1.setOnClickListener(myListener); button1.setOnClickListener(this); myLayout.addView(bannerText); myLayout.addView(input1); myLayout.addView(output1); myLayout.addView(button1); LinearLayout.LayoutParams parm = new RadioGroup.LayoutParams(300, 100); input1.setLayoutParams(parm); output1.setLayoutParams(parm); button1.setLayoutParams(parm); setContentView(myLayout); input1.setLayoutParams(new LinearLayout.LayoutParams(225, 50)); button1.setLayoutParams(new LinearLayout.LayoutParams(170, 50)); // button2.setLayoutParams(new LinearLayout.LayoutParams(170, 50)); }
@Override protected void onCreate(Bundle state) { super.onCreate(state); setRequestedOrientation(SCREEN_ORIENTATION_NOSENSOR); String qrData = getIntent().getStringExtra(Intent.EXTRA_TEXT); cameraView = new CameraView(this); cameraBorder = new LinearLayout(this); cameraBorder.setGravity(CENTER); cameraBorder.setBackgroundColor(BLACK); cameraBorder.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT, 1f)); cameraBorder.addView(cameraView); ImageView qrCodeView = new ImageView(this); qrCodeView.setScaleType(FIT_CENTER); qrCodeView.setBackgroundColor(WHITE); qrCodeView.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT, 1f)); Display display = getWindowManager().getDefaultDisplay(); boolean portrait = display.getWidth() < display.getHeight(); layoutMain = new LinearLayout(this); if (portrait) layoutMain.setOrientation(VERTICAL); else layoutMain.setOrientation(HORIZONTAL); layoutMain.setWeightSum(2); layoutMain.addView(cameraBorder); layoutMain.addView(qrCodeView); setContentView(layoutMain); new QrGenAsyncTask(this, qrCodeView).execute(qrData); }
private void init(Context context, int color) { // To fight color branding. getWindow().setFormat(PixelFormat.RGBA_8888); final LinearLayout mContentView = new LinearLayout(context); mContentView.setGravity(Gravity.CENTER); mColorPicker = new ColorPickerView(context); mContentView.addView(mColorPicker, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mContentView.setPadding( Math.round(mColorPicker.getDrawingOffset()), 0, Math.round(mColorPicker.getDrawingOffset()), 0); mColorPicker.setOnColorChangedListener(this); mColorPicker.setColor(color, true); mColorPicker.setAlphaSliderVisible(true); setTitle(R.string.pick_color); setView(mContentView); setButton(BUTTON_POSITIVE, context.getString(android.R.string.ok), this); setButton(BUTTON_NEGATIVE, context.getString(android.R.string.cancel), this); }
public void addNavBar(String title, Map<Object, Object> left, Map<Object, Object> right) { removeNavBar(); Context ctx = RhodesActivity.getContext(); LinearLayout top = new LinearLayout(ctx); top.setOrientation(LinearLayout.HORIZONTAL); top.setBackgroundColor(Color.GRAY); top.setGravity(Gravity.CENTER); top.setLayoutParams(new LinearLayout.LayoutParams(FILL_PARENT, WRAP_CONTENT, 0)); View leftButton = createButton(left); leftButton.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1)); top.addView(leftButton); TextView label = new TextView(ctx); label.setText(title); label.setGravity(Gravity.CENTER); label.setTextSize((float) 30.0); label.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 2)); top.addView(label); if (right != null) { View rightButton = createButton(right); rightButton.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1)); top.addView(rightButton); } navBar = top; view.addView(navBar, 0); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); LinearLayout ll = new LinearLayout(getActivity()); ll.setOrientation(LinearLayout.VERTICAL); ll.setGravity(Gravity.BOTTOM); mSeekBarZ = new SeekBar(getActivity()); mSeekBarZ.setMax(40); mSeekBarZ.setProgress(16); mSeekBarZ.setOnSeekBarChangeListener(this); ll.addView(mSeekBarZ); mSeekBarY = new SeekBar(getActivity()); mSeekBarY.setMax(20); mSeekBarY.setProgress(13); mSeekBarY.setOnSeekBarChangeListener(this); ll.addView(mSeekBarY); mSeekBarX = new SeekBar(getActivity()); mSeekBarX.setMax(20); mSeekBarX.setProgress(10); mSeekBarX.setOnSeekBarChangeListener(this); ll.addView(mSeekBarX); mLayout.addView(ll); return mLayout; }
@Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { LinearLayout itemView = new LinearLayout(parent.getContext()); TextView textView = new TextView(parent.getContext()); textView.setTextSize(18); textView.setId(android.R.id.text1); RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, Converter.dp2px(itemView.getContext(), 56)); itemView.setPadding( Converter.dp2px(itemView.getContext(), 16), 0, Converter.dp2px(itemView.getContext(), 16), 0); itemView.setGravity(Gravity.LEFT | Gravity.START | Gravity.CENTER); itemView.setBackgroundResource(R.drawable.touch_feedback_holo_light); itemView.addView(textView); itemView.setLayoutParams(layoutParams); if (this.layoutManager instanceof GridLayoutManager) { calculateGridItemSize(itemView); } return new ViewHolder(itemView); }
private LinearLayout getTriggerStatuslayout(Trigger trigger) { LinearLayout triggerStatusLayout = new LinearLayout(ctx); triggerStatusLayout.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); triggerStatusLayout.setGravity(Gravity.CENTER); triggerStatusLayout.setOrientation(VERTICAL); ImageView triggerAckImg = new ImageView(ctx); triggerAckImg.setImageResource(trigger.getAckImg()); triggerAckImg.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); triggerAckImg.setPadding(0, 5, 0, 0); ImageView triggerStatusImage = new ImageView(ctx); triggerStatusImage.setImageResource(trigger.getActiveImg()); triggerStatusImage.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); triggerStatusLayout.addView(triggerStatusImage); if (!showask()) { triggerStatusLayout.addView(triggerAckImg); // triggerStatusLayout.setGravity(Gravity.RIGHT); triggerStatusLayout.setPadding(0, 10, 0, 0); } else { // triggerStatusLayout.setGravity(Gravity.RIGHT); triggerStatusLayout.setPadding(0, 20, 0, 10); } return triggerStatusLayout; }