android.widget.TextView.setLayoutParams()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(288)

本文整理了Java中android.widget.TextView.setLayoutParams()方法的一些代码示例,展示了TextView.setLayoutParams()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.setLayoutParams()方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:setLayoutParams

TextView.setLayoutParams介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

LayoutParams lparams = new LayoutParams(
  LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView tv=new TextView(this);
tv.setLayoutParams(lparams);
tv.setText("test");
this.m_vwJokeLayout.addView(tv);

代码示例来源:origin: gzu-liyujiang/AndroidPicker

protected TextView createLabelView() {
  TextView labelView = new TextView(activity);
  labelView.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
  labelView.setTextColor(labelTextColor);
  labelView.setTextSize(textSize);
  return labelView;
}

代码示例来源:origin: lygttpod/SuperTextView

/**
 * 初始化textView
 *
 * @param textView     对象
 * @param layoutParams 对象
 * @return 返回
 */
public TextView getTextView(TextView textView, LinearLayout.LayoutParams layoutParams) {
  if (textView == null) {
    textView = new TextView(mContext);
    textView.setLayoutParams(layoutParams);
    textView.setVisibility(GONE);
  }
  return textView;
}

代码示例来源:origin: stackoverflow.com

private static SpannableStringBuilder addClickablePartTextViewResizable(final Spanned strSpanned, final TextView tv,
                                     final int maxLine, final String spanableText, final boolean viewMore) {
   String str = strSpanned.toString();
   SpannableStringBuilder ssb = new SpannableStringBuilder(strSpanned);
   if (str.contains(spanableText)) {
     ssb.setSpan(new MySpannable(false){
       @Override
       public void onClick(View widget) {
         if (viewMore) {
           tv.setLayoutParams(tv.getLayoutParams());
           tv.setText(tv.getTag().toString(), BufferType.SPANNABLE);
           tv.invalidate();
           makeTextViewResizable(tv, -1, "View Less", false);
         } else {
           tv.setLayoutParams(tv.getLayoutParams());
           tv.setText(tv.getTag().toString(), BufferType.SPANNABLE);
           tv.invalidate();
           makeTextViewResizable(tv, 3, "View More", true);
         }
       }
     }, str.indexOf(spanableText), str.indexOf(spanableText) + spanableText.length(), 0);
   }
   return ssb;
 }

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
 * 初始化viwe
 */
private void findViews() {
  LayoutInflater inflater = (LayoutInflater) getContext()
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  inflater.inflate(R.layout.item_expand_shink, this);
  mTvContent = (TextView) findViewById(R.id.expandable_text);
  mTvContent.setOnClickListener(this);
  mTvExpandCollapse = (TextView) findViewById(R.id.expand_collapse);
  if(showExpandCollapseDrawable) {
    mTvExpandCollapse.setCompoundDrawablesWithIntrinsicBounds(null, null, mCollapsed ? mExpandDrawable : mCollapseDrawable, null);
  }
  mTvExpandCollapse.setText(mCollapsed ? getResources().getString(R.string.expand) : getResources().getString(R.string.shink));
  mTvExpandCollapse.setOnClickListener(this);
  mTvContent.setTextColor(contentTextColor);
  mTvContent.getPaint().setTextSize(contentTextSize);
  mTvExpandCollapse.setTextColor(collapseExpandTextColor);
  mTvExpandCollapse.getPaint().setTextSize(collapseExpandTextSize);
  //设置收起展开位置:左或者右
  LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
  lp.gravity = grarity;
  mTvExpandCollapse.setLayoutParams(lp);
}
/**

代码示例来源:origin: gzu-liyujiang/AndroidPicker

if (!TextUtils.isEmpty(firstPrefixLabel)) {
  TextView firstPrefixLabelView = createLabelView();
  firstPrefixLabelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
  firstPrefixLabelView.setText(firstPrefixLabel);
  layout.addView(firstPrefixLabelView);
layout.addView(firstView);
if (!TextUtils.isEmpty(firstSuffixLabel)) {
  TextView firstSuffixLabelView = createLabelView();
  firstSuffixLabelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
  firstSuffixLabelView.setText(firstSuffixLabel);
  layout.addView(firstSuffixLabelView);
  secondPrefixLabelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
  secondPrefixLabelView.setText(secondPrefixLabel);
  layout.addView(secondPrefixLabelView);
if (!TextUtils.isEmpty(secondSuffixLabel)) {
  TextView secondSuffixLabelView = createLabelView();
  secondSuffixLabelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
  secondSuffixLabelView.setText(secondSuffixLabel);
  layout.addView(secondSuffixLabelView);

代码示例来源:origin: H07000223/FlycoDialog_Master

@Override
public View onCreateView() {
  LinearLayout ll_container = new LinearLayout(mContext);
  ll_container.setOrientation(LinearLayout.VERTICAL);
  /** title */
  mTvTitle = new TextView(mContext);
  mTvTitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
      LinearLayout.LayoutParams.WRAP_CONTENT));
  mTvTitle.setSingleLine(true);
  mTvTitle.setPadding(dp2px(18), dp2px(10), 0, dp2px(10));
  ll_container.addView(mTvTitle);
  /** listview */
  mLv = new ListView(mContext);
  mLv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
      LinearLayout.LayoutParams.WRAP_CONTENT));
  mLv.setCacheColorHint(Color.TRANSPARENT);
  mLv.setFadingEdgeLength(0);
  mLv.setVerticalScrollBarEnabled(false);
  mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));
  ll_container.addView(mLv);
  return ll_container;
}

代码示例来源:origin: GitLqr/LQRWeChat

@Override
public void initView(View rootView) {
  mHeaderView = View.inflate(getActivity(), R.layout.header_rv_contacts, null);
  mTvNewFriendUnread = (TextView) mHeaderView.findViewById(R.id.tvNewFriendUnread);
  mFooterView = new TextView(getContext());
  ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, UIUtils.dip2Px(50));
  mFooterView.setLayoutParams(params);
  mFooterView.setGravity(Gravity.CENTER);
  registerBR();
}

代码示例来源:origin: H07000223/FlycoDialog_Master

@Override
public View onCreateView() {
  /** title */
  mTvTitle.setGravity(Gravity.CENTER_VERTICAL);
  mTvTitle.setPadding(dp2px(20), dp2px(20), dp2px(20), dp2px(0));
  mTvTitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
      LinearLayout.LayoutParams.WRAP_CONTENT));
  mLlContainer.addView(mTvTitle);
  /** content */
  mTvContent.setPadding(dp2px(20), dp2px(20), dp2px(20), dp2px(20));
  mTvContent.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
      LinearLayout.LayoutParams.WRAP_CONTENT));
  mLlContainer.addView(mTvContent);
  /**btns*/
  mLlBtns.setGravity(Gravity.RIGHT);
  mLlBtns.addView(mTvBtnLeft);
  mLlBtns.addView(mTvBtnMiddle);
  mLlBtns.addView(mTvBtnRight);
  mTvBtnLeft.setPadding(dp2px(15), dp2px(8), dp2px(15), dp2px(8));
  mTvBtnRight.setPadding(dp2px(15), dp2px(8), dp2px(15), dp2px(8));
  mTvBtnMiddle.setPadding(dp2px(15), dp2px(8), dp2px(15), dp2px(8));
  mLlBtns.setPadding(dp2px(20), dp2px(0), dp2px(10), dp2px(10));
  mLlContainer.addView(mLlBtns);
  return mLlContainer;
}

代码示例来源:origin: Ramotion/expanding-collection-android

private TextView createViewForTextSwitcher(Context context) {
  TextView textView = new TextView(context);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    textView.setTextAppearance(R.style.positionIndicatorCurrent);
  } else {
    textView.setTextAppearance(context, R.style.positionIndicatorCurrent);
  }
  textView.setLayoutParams(new TextSwitcher.LayoutParams(TextSwitcher.LayoutParams.WRAP_CONTENT, TextSwitcher.LayoutParams.WRAP_CONTENT));
  return textView;
}

代码示例来源:origin: H07000223/FlycoDialog_Master

@Override
public View onCreateView() {
  mTvTitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
      LinearLayout.LayoutParams.WRAP_CONTENT));
  mLlContainer.addView(mTvTitle);
  mLlContainer.addView(mVLineTitle);
  mTvContent.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
      LinearLayout.LayoutParams.WRAP_CONTENT));
  mLlContainer.addView(mTvContent);
  mTvBtnLeft.setLayoutParams(new LinearLayout.LayoutParams(0, dp2px(45), 1));
  mLlBtns.addView(mTvBtnLeft);
  mLlBtns.addView(mVLineVertical);
  mTvBtnMiddle.setLayoutParams(new LinearLayout.LayoutParams(0, dp2px(45), 1));
  mLlBtns.addView(mTvBtnMiddle);
  mLlBtns.addView(mVLineVertical2);
  mTvBtnRight.setLayoutParams(new LinearLayout.LayoutParams(0, dp2px(45), 1));
  mLlBtns.addView(mTvBtnRight);

代码示例来源:origin: stackoverflow.com

LinearLayout layout = (LinearLayout) findViewById(R.id.your_layout_id);
TextView tv = new TextView(this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv.setText("Added tv");
layout.addView(tv);

代码示例来源:origin: stackoverflow.com

ViewGroup layout = (ViewGroup) findViewById(R.id.your_layout_id);
TextView tv = new TextView(this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv.setText("Added tv");
layout.addView(tv);

代码示例来源:origin: TeamNewPipe/NewPipe

@Override
public void onProgressUpdate(int currentProgress, int duration, int bufferPercent) {
  // Set buffer progress
  progressSeekBar.setSecondaryProgress((int) (progressSeekBar.getMax() * ((float) bufferPercent / 100)));
  // Set Duration
  progressSeekBar.setMax(duration);
  progressEndTime.setText(Localization.getDurationString(duration / 1000));
  // Set current time if not seeking
  if (!seeking) {
    progressSeekBar.setProgress(currentProgress);
    progressCurrentTime.setText(Localization.getDurationString(currentProgress / 1000));
  }
  if (player != null) {
    progressLiveSync.setClickable(!player.isLiveEdge());
  }
  // this will make shure progressCurrentTime has the same width as progressEndTime
  final ViewGroup.LayoutParams endTimeParams = progressEndTime.getLayoutParams();
  final ViewGroup.LayoutParams currentTimeParams = progressCurrentTime.getLayoutParams();
  currentTimeParams.width = progressEndTime.getWidth();
  progressCurrentTime.setLayoutParams(currentTimeParams);
}

代码示例来源:origin: H07000223/FlycoTabLayout

@Override
  public View getView(int position, View convertView, ViewGroup parent) {

    int padding = (int) (mDisplayMetrics.density * 10);

    TextView tv = new TextView(mContext);
    tv.setText(mItems[position]);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    tv.setTextColor(Color.parseColor("#468ED0"));
    // tv.setGravity(Gravity.CENTER);
    tv.setPadding(padding, padding, padding, padding);
    AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
        AbsListView.LayoutParams.WRAP_CONTENT);
    tv.setLayoutParams(lp);
    return tv;
  }
}

代码示例来源:origin: stackoverflow.com

TextView tv1 = new TextView(this);
tv1.setLayoutParams(textOutLayoutParams);
tv1.setText(Html.fromHtml("<a href=\""+ l.getRightString() + "\">" + l.getLeftString() + "</a>"));
tv1.setClickable(true);
tv1.setMovementMethod (LinkMovementMethod.getInstance());
dialogLayout.addView(tv1);

代码示例来源:origin: navasmdc/MaterialDesignLibrary

params.height = (int) finalSize * 2;
params.width = (int) finalSize * 2;
numberIndicator.numberIndicator.setLayoutParams(params);
            - size);
ViewHelper.setY(numberIndicator.numberIndicator, y - size);
numberIndicator.numberIndicator.setText(value + "");

代码示例来源:origin: stackoverflow.com

private TextView noItems(String text) {
  TextView emptyView = new TextView(getActivity());
  //Make sure you import android.widget.LinearLayout.LayoutParams;
  emptyView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
      LayoutParams.MATCH_PARENT));
  //Instead of passing resource id here I passed resolved color 
  //That is, getResources().getColor((R.color.gray_dark))
  emptyView.setTextColor(getResources().getColor(R.color.gray_dark));
  emptyView.setText(text);
  emptyView.setTextSize(12);
  emptyView.setVisibility(View.GONE);
  emptyView.setGravity(Gravity.CENTER_VERTICAL
      | Gravity.CENTER_HORIZONTAL);

  //Add the view to the list view. This might be what you are missing
  ((ViewGroup) getListView().getParent()).addView(emptyView);

  return emptyView;
}

代码示例来源:origin: stackoverflow.com

TextView tv = new TextView(this);
tv.setText("Test");
tv.setLayoutParams(lp);

代码示例来源:origin: H07000223/FlycoDialog_Master

@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    int padding = (int) (mDisplayMetrics.density * 10);
    TextView tv = new TextView(mContext);
    tv.setText(mItems[position]);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    tv.setTextColor(Color.parseColor("#468ED0"));
    // tv.setGravity(Gravity.CENTER);
    tv.setPadding(padding, padding, padding, padding);
    AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
        AbsListView.LayoutParams.WRAP_CONTENT);
    tv.setLayoutParams(lp);
    return tv;
  }
}

相关文章

TextView类方法