Java Code Examples for android.widget.TextView#setLayoutParams()
The following examples show how to use
android.widget.TextView#setLayoutParams() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: SweetTips File: SweetToast.java License: Apache License 2.0 | 6 votes |
/** * 设置当前SweetToast实例的最小宽高 * 很有用的功能,参考了简书上的文章:http://www.jianshu.com/p/491b17281c0a * @param width SweetToast实例的最小宽度,单位是pix * @param height SweetToast实例的最小高度,单位是pix * @return */ public SweetToast minSize(int width, int height){ if(mContentView!=null && mContentView instanceof LinearLayout){ mContentView.setMinimumWidth(width); mContentView.setMinimumHeight(height); ((LinearLayout)mContentView).setGravity(Gravity.CENTER); try { TextView textView = ((TextView) mContentView.findViewById(R.id.message)); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textView.getLayoutParams(); params.width = LinearLayout.LayoutParams.MATCH_PARENT; params.height = LinearLayout.LayoutParams.MATCH_PARENT; textView.setLayoutParams(params); textView.setGravity(Gravity.CENTER); }catch (Exception e){ Log.e("幻海流心","e:"+e.getLocalizedMessage()); } } return this; }
Example 2
Source Project: SI File: PageHandler.java License: BSD 2-Clause "Simplified" License | 6 votes |
protected void appendRow( String value ){ // create table row TableLayout tb = (TableLayout)findViewById(R.id.control_table_layout); TableRow tableRow = new TableRow(this); tableRow.setLayoutParams(tableLayout); // get current time long time = System.currentTimeMillis(); SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String cur_time = dayTime.format(new Date(time)); // set Text on TextView TextView tv_left = new TextView(this); tv_left.setText( cur_time ); tv_left.setLayoutParams( tableRowLayout ); tableRow.addView( tv_left ); TextView tv_right = new TextView(this); tv_right.setText( value ); tv_right.setLayoutParams( tableRowLayout ); tableRow.addView( tv_right ); // set table rows on table tb.addView(tableRow); }
Example 3
Source Project: imsdk-android File: QuickReplyLayout.java License: MIT License | 6 votes |
private void initTabLayout() { if (quickReplies != null && quickReplies.keySet().size() > 0) { tabLayout.removeAllViews(); for (String s : quickReplies.keySet()) { TextView textView = new TextView(context); textView.setLayoutParams(new LayoutParams(Utils.getScreenWidth(context) / 4, ViewGroup.LayoutParams.MATCH_PARENT)); textView.setText(s); textView.setMaxLines(1); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setTag(s); textView.setPadding(8, 0, 8, 0); textView.setGravity(Gravity.CENTER); textView.setOnClickListener(new TabOnClickListener()); TextView splitView = new TextView(context); splitView.setLayoutParams(new LayoutParams(Utils.dpToPx(context, 1), ViewGroup.LayoutParams.MATCH_PARENT)); splitView.setBackgroundResource(R.color.atom_ui_light_gray_DD); tabLayout.addView(textView); tabLayout.addView(splitView); } selectedTab = tabLayout.getChildAt(0); selectedTab.setBackgroundResource(selectTabColor); } }
Example 4
Source Project: letv File: NewFeatureActivity.java License: Apache License 2.0 | 6 votes |
public void updateUI() { this.recoAppName.setText(this.mrecoApp.getName()); String[] split = this.mrecoApp.getDesc().split("/"); if (split.length == 2) { this.reco_desp.setPadding(0, 0, 0, 60); } for (CharSequence text : split) { TextView tv = new TextView(this); tv.setLayoutParams(new LayoutParams(-1, -1, 1.0f)); tv.setShadowLayer(3.0f, 3.0f, 1.0f, 2131493090); tv.setTextColor(-1); tv.setGravity(1); tv.setText(text); tv.setTextSize(18.0f); this.reco_desp.addView(tv); } }
Example 5
Source Project: ZoomHeaderViewPager File: ViewPagerHeader.java License: Apache License 2.0 | 6 votes |
private TextView createHeaderItem(int position, String headerText) { TextView header = new TextView(getContext()); LayoutParams linearParams = new LayoutParams(headerWidth / headerPerView, LayoutParams.WRAP_CONTENT); header.setLayoutParams(linearParams); header.setScaleX(textViewAttr.getHvMinScale()); header.setScaleY(textViewAttr.getHvMinScale()); header.setAlpha(textViewAttr.getHvTextAlpha()); header.setTextColor(textViewAttr.getHvTextColor()); header.setPadding(0, (int) textViewAttr.getHvPadding(), 0, (int) textViewAttr.getHvPadding()); header.setMaxLines(1); header.setGravity(Gravity.CENTER); header.setEllipsize(TextUtils.TruncateAt.END); header.setText(headerText); header.setTextSize(TypedValue.COMPLEX_UNIT_PX, textViewAttr.getHvTextSize()); textViews[position] = header; return header; }
Example 6
Source Project: WhatsappFormatter File: MainActivity.java License: Apache License 2.0 | 6 votes |
private void addView() { String text = mEditText.getText().toString(); TextView textView = new TextView(this); textView.setBackgroundResource(R.drawable.ic_whatsapp_chathead); textView.setText(text); textView.setPadding(10, 10, 40, 10); mContainer.addView(textView); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams.gravity = Gravity.END; layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT; layoutParams.topMargin = layoutParams.rightMargin = layoutParams.bottomMargin = layoutParams.leftMargin = 20; textView.setGravity(Gravity.START | Gravity.CENTER); textView.setLayoutParams(layoutParams); WhatsappViewCompat.applyFormatting(textView); mEditText.setText(""); }
Example 7
Source Project: AndroidStarterKit File: SlidingTabLayout.java License: MIT License | 6 votes |
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}. */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
Example 8
Source Project: AndroidProject File: AddressDialog.java License: Apache License 2.0 | 5 votes |
@NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) { TextView textView = new TextView(parent.getContext()); textView.setGravity(Gravity.CENTER_VERTICAL); textView.setBackgroundResource(R.drawable.selector_transparent); textView.setTextColor(0xFF222222); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); textView.setPadding((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()), (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics()), (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()), (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics())); return new ViewHolder(textView); }
Example 9
Source Project: SmartChart File: SmartTabLayout.java License: Apache License 2.0 | 5 votes |
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}. */ protected TextView createDefaultTabView(CharSequence title) { TextView textView = new TextView(getContext()); textView.setGravity(Gravity.CENTER); textView.setText(title); textView.setTextColor(tabViewTextColors); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); if (tabViewBackgroundResId != NO_ID) { textView.setBackgroundResource(tabViewBackgroundResId); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(tabViewTextAllCaps); } textView.setPadding( tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0); if (tabViewTextMinWidth > 0) { textView.setMinWidth(tabViewTextMinWidth); } return textView; }
Example 10
Source Project: RxTools-master File: RxPopupViewCoordinatesFinder.java License: Apache License 2.0 | 5 votes |
private static void AdjustRightToOutOfBounds(TextView tipView, ViewGroup root, Point point, RxCoordinates anchorViewRxCoordinates, RxCoordinates rootLocation) { ViewGroup.LayoutParams params = tipView.getLayoutParams(); int availableSpace = rootLocation.right - root.getPaddingRight() - anchorViewRxCoordinates.right; if (point.x + tipView.getMeasuredWidth() > rootLocation.right - root.getPaddingRight()){ params.width = availableSpace; params.height = ViewGroup.LayoutParams.WRAP_CONTENT; tipView.setLayoutParams(params); measureViewWithFixedWidth(tipView, params.width); } }
Example 11
Source Project: LazyRecyclerAdapter File: BindCustomLoadMoreFooter.java License: MIT License | 5 votes |
/** * 初始化view */ void initView() { setGravity(Gravity.CENTER); setLayoutParams(new RecyclerView.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); setPadding(0, (int) getResources().getDimension(R.dimen.textandiconmargin), 0, (int) getResources().getDimension(R.dimen.textandiconmargin)); mImageView = new ImageView(getContext()); mImageView.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mImageView.setImageResource(R.drawable.progressbar); addView(mImageView); mText = new TextView(getContext()); mText.setText("正在加载..."); LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.setMargins((int) getResources().getDimension(R.dimen.textandiconmargin), 0, 0, 0); mText.setLayoutParams(layoutParams); addView(mText); mAnimationDrawable = (AnimationDrawable) mImageView.getDrawable(); }
Example 12
Source Project: SprintNBA File: IndexableStickyListView.java License: Apache License 2.0 | 5 votes |
private void initOverlayTextView() { mTvOverlay = new TextView(mContext); mTvOverlay.setBackgroundResource(R.drawable.bg_translucent_4dp); mTvOverlay.setTextColor(Color.WHITE); mTvOverlay.setTextSize(40); mTvOverlay.setGravity(Gravity.CENTER); int size = IndexBar.dp2px(mContext, 70); LayoutParams params = new LayoutParams(size, size); params.gravity = Gravity.CENTER; mTvOverlay.setLayoutParams(params); mTvOverlay.setVisibility(INVISIBLE); }
Example 13
Source Project: Mysplash File: RippleButton.java License: GNU Lesser General Public License v3.0 | 5 votes |
private void initialize(AttributeSet attrs, int defStyleAttr) { utils = new DisplayUtils(getContext()); text = new TextView(getContext()); text.setTypeface(Typeface.DEFAULT_BOLD); text.setGravity(Gravity.CENTER); text.setLines(1); LayoutParams textParams = new LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ); textParams.gravity = Gravity.CENTER; text.setLayoutParams(textParams); addView(text); ripple = new RippleView(getContext()); LayoutParams rippleParams = new LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ); rippleParams.gravity = Gravity.CENTER; ripple.setLayoutParams(rippleParams); addView(ripple); progress = new CircularProgressView(getContext()); progress.setIndeterminate(true); progress.setColor(Color.DKGRAY); LayoutParams progressParams = new LayoutParams( getResources().getDimensionPixelSize(R.dimen.mini_icon_size), getResources().getDimensionPixelSize(R.dimen.mini_icon_size) ); progressParams.gravity = Gravity.CENTER; progress.setLayoutParams(progressParams); addView(progress); initData(attrs, defStyleAttr); initWidget(); }
Example 14
Source Project: slidingtabs File: SlidingTabLayout.java License: Apache License 2.0 | 5 votes |
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}. */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); TypedValue outValue = new TypedValue(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); } textView.setBackgroundResource(outValue.resourceId); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
Example 15
Source Project: DropDownMenu File: DropDownMenu.java License: Apache License 2.0 | 5 votes |
private void addTab(@NonNull List<String> tabTexts, int i) { final TextView tab = new TextView(getContext()); tab.setSingleLine(); tab.setEllipsize(TextUtils.TruncateAt.END); tab.setGravity(Gravity.CENTER); tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize); tab.setLayoutParams(new LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f)); tab.setTextColor(textUnselectedColor); tab.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(menuUnselectedIcon), null); tab.setText(tabTexts.get(i)); tab.setPadding(dpTpPx(5), dpTpPx(12), dpTpPx(5), dpTpPx(12)); //添加点击事件 tab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { switchMenu(tab); } }); tabMenuView.addView(tab); tabMenuView.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); tabMenuView.setDividerDrawable(getResources().getDrawable(R.drawable.divider_line)); //添加分割线 /* if (i < tabTexts.size() - 1) { View view = new View(getContext()); view.setLayoutParams(new LayoutParams(dpTpPx(0.5f), ViewGroup.LayoutParams.MATCH_PARENT)); view.setBackgroundColor(dividerColor); tabMenuView.addView(view); }*/ }
Example 16
Source Project: TitleBar File: ViewCore.java License: Apache License 2.0 | 5 votes |
static TextView newRightView(Context context) { TextView rightView = new TextView(context); rightView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); rightView.setGravity(Gravity.CENTER_VERTICAL); rightView.setFocusable(true); rightView.setClickable(true); rightView.setSingleLine(); rightView.setEllipsize(TextUtils.TruncateAt.END); return rightView; }
Example 17
Source Project: nono-android File: PinViewBaseHelper.java License: GNU General Public License v3.0 | 5 votes |
/** * Set a Split with all attributes * * @param split to set attributes */ private void setStylesSplit(TextView split) { if(split!=null){ split.setText(mSplit); split.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); split.setGravity(Gravity.CENTER_VERTICAL); if (mColorSplit != PinViewSettings.DEFAULT_COLOR_SPLIT) { split.setTextColor(mColorSplit); } split.setTextSize(PinViewUtils.convertPixelToDp(getContext(), mSizeSplit)); } }
Example 18
Source Project: SimpleAdapterDemo File: SimpleAdapter.java License: Apache License 2.0 | 4 votes |
@NonNull @Override public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) { BaseViewHolder holder = null; switch (viewType) { case TYPE_HEADER: if (getHeaderLayoutId() == -1) throw new IllegalArgumentException(getClass().getSimpleName() + " : please set header layout first."); holder = new BaseViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(getHeaderLayoutId(), viewGroup, false)); if (getOnCreateViewHolderListener() != null) { getOnCreateViewHolderListener().onCreateHeaderViewHolder(holder); } break; case TYPE_DATA: if (getDataLayoutId() == -1) throw new IllegalArgumentException(getClass().getSimpleName() + " : please set footer layout first."); holder = new BaseViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(getDataLayoutId(), viewGroup, false)); if (getOnCreateViewHolderListener() != null) { getOnCreateViewHolderListener().onCreateDataViewHolder(holder); } break; case TYPE_FOOTER: if (getFooterLayoutId() == -1) throw new IllegalArgumentException(getClass().getSimpleName() + " : please set footer layout first."); holder = new BaseViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(getFooterLayoutId(), viewGroup, false)); if (getOnCreateViewHolderListener() != null) { getOnCreateViewHolderListener().onCreateFooterViewHolder(holder); } break; case TYPE_EMPTY: holder = new BaseViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(getEmptyLayoutId() == -1 ? R.layout.recycler_default_empty_list_layout : getEmptyLayoutId(), viewGroup, false)); if (getOnCreateViewHolderListener() != null) { getOnCreateViewHolderListener().onCreateEmptyViewHolder(holder); } break; default: TextView textView = new TextView(viewGroup.getContext()); textView.setTextColor(Color.RED); textView.setGravity(Gravity.CENTER); textView.setText("Unknown view type"); textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); holder = new BaseViewHolder(textView); break; } return holder; }
Example 19
Source Project: adt-leanback-support File: AbstractDetailsDescriptionPresenter.java License: Apache License 2.0 | 4 votes |
private void setTopMargin(TextView textView, int topMargin) { ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) textView.getLayoutParams(); lp.topMargin = topMargin; textView.setLayoutParams(lp); }
Example 20
Source Project: WeCenterMobile-Android File: PlatformGridView.java License: GNU General Public License v2.0 | 4 votes |
private LinearLayout getView(int position, OnClickListener ocL, Context context) { Bitmap logo; String label; OnClickListener listener; if (beans[position] instanceof Platform) { logo = getIcon((Platform) beans[position]); label = getName((Platform) beans[position]); listener = ocL; } else { logo = ((CustomerLogo) beans[position]).logo; label = ((CustomerLogo) beans[position]).label; listener = ((CustomerLogo) beans[position]).listener; } LinearLayout ll = new LinearLayout(context); ll.setOrientation(LinearLayout.VERTICAL); ImageView iv = new ImageView(context); int dp_5 = cn.sharesdk.framework.utils.R.dipToPx(context, 5); iv.setPadding(dp_5, dp_5, dp_5, dp_5); iv.setScaleType(ScaleType.CENTER_INSIDE); LinearLayout.LayoutParams lpIv = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpIv.setMargins(dp_5, dp_5, dp_5, dp_5); lpIv.gravity = Gravity.CENTER_HORIZONTAL; iv.setLayoutParams(lpIv); iv.setImageBitmap(logo); ll.addView(iv); TextView tv = new TextView(context); tv.setTextColor(0xffffffff); tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); tv.setSingleLine(); tv.setIncludeFontPadding(false); LinearLayout.LayoutParams lpTv = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpTv.gravity = Gravity.CENTER_HORIZONTAL; lpTv.weight = 1; lpTv.setMargins(dp_5, 0, dp_5, dp_5); tv.setLayoutParams(lpTv); tv.setText(label); ll.addView(tv); ll.setOnClickListener(listener); return ll; }