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

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

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

TextView.getLayoutParams介绍

暂无

代码示例

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

TextView tv = (TextView)findViewById(R.id.my_text_view);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)tv.getLayoutParams();
params.setMargins(0, 0, 10, 0); //substitute parameters for left, top, right, bottom
tv.setLayoutParams(params);

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

TextView textView = (TextView)findViewById(R.id.text_view);
ViewGroup.LayoutParams params = textView.getLayoutParams();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
textView.setLayoutParams(params);

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

myActionBar.setIcon(new ColorDrawable(Color.TRANSPARENT));

private void centerActionBarTitle() {
  int titleId = 0;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    titleId = getResources().getIdentifier("action_bar_title", "id", "android");
  } else {
    // This is the id is from your app's generated R class when 
    // ActionBarActivity is used for SupportActionBar
    titleId = R.id.action_bar_title;
  }

  // Final check for non-zero invalid id
  if (titleId > 0) {
    TextView titleTextView = (TextView) findViewById(titleId);
    DisplayMetrics metrics = getResources().getDisplayMetrics();

    // Fetch layout parameters of titleTextView 
    // (LinearLayout.LayoutParams : Info from HierarchyViewer)
    LinearLayout.LayoutParams txvPars = (LayoutParams) titleTextView.getLayoutParams();
    txvPars.gravity = Gravity.CENTER_HORIZONTAL;
    txvPars.width = metrics.widthPixels;
    titleTextView.setLayoutParams(txvPars);
    titleTextView.setGravity(Gravity.CENTER);
  }
}

代码示例来源:origin: akexorcist/Android-RoundCornerProgressBar

private void drawTextProgressMargin() {
  ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) tvProgress.getLayoutParams();
  params.setMargins(textProgressMargin, 0, textProgressMargin, 0);
  tvProgress.setLayoutParams(params);
}

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

final SimpleCursorAdapter adapter = new SimpleCursorAdapter (context, cursor) {
  @Override
  public View getView (int position, View convertView, ViewGroup parent) {
    final View view = super.getView(position, convertView, parent);
    final TextView text = (TextView) view.findViewById(R.id.tvRow);
    final LayoutParams params = text.getLayoutParams();

    if (params != null) {
        params.height = mRowHeight;
    }

    return view;
  }
}

代码示例来源:origin: akexorcist/Android-RoundCornerProgressBar

private void alignTextProgressInsideProgress() {
  RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tvProgress.getLayoutParams();
  if (isReverse()) {
    params.addRule(RelativeLayout.ALIGN_LEFT, R.id.layout_progress);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
      params.addRule(RelativeLayout.ALIGN_START, R.id.layout_progress);
  } else {
    params.addRule(RelativeLayout.ALIGN_RIGHT, R.id.layout_progress);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
      params.addRule(RelativeLayout.ALIGN_END, R.id.layout_progress);
  }
  tvProgress.setLayoutParams(params);
}

代码示例来源:origin: akexorcist/Android-RoundCornerProgressBar

private void alignTextProgressOutsideProgress() {
  RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tvProgress.getLayoutParams();
  if (isReverse()) {
    params.addRule(RelativeLayout.LEFT_OF, R.id.layout_progress);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
      params.addRule(RelativeLayout.START_OF, R.id.layout_progress);
  } else {
    params.addRule(RelativeLayout.RIGHT_OF, R.id.layout_progress);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
      params.addRule(RelativeLayout.END_OF, R.id.layout_progress);
  }
  tvProgress.setLayoutParams(params);
}

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

TextView tv = new TextView(this);
tv.setLayoutParams(new ViewGroup.LayoutParams(
    ViewGroup.LayoutParams.WRAP_CONTENT,
    ViewGroup.LayoutParams.WRAP_CONTENT));

llview.addView(tv);
tv.setTextColor(Color.WHITE);
tv.setTextSize(2,25);
tv.setText(chat);
if (mine) {
  leftMargin = 5;
  tv.setBackgroundColor(0x7C5B77);
}
else {
  leftMargin = 50;
  tv.setBackgroundColor(0x778F6E);
}
final ViewGroup.MarginLayoutParams lpt =(MarginLayoutParams)tv.getLayoutParams();
lpt.setMargins(leftMargin,lpt.topMargin,lpt.rightMargin,lpt.bottomMargin);

代码示例来源: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: fython/MaterialStepperView

@Override
  public void onGlobalLayout() {
    int singleLineHeight = mTitleText.getMeasuredHeight();
    int topMargin = (mPointFrame.getMeasuredHeight() - singleLineHeight) / 2;
    // Only update top margin when it is positive, preventing titles being truncated.
    if (topMargin > 0) {
      ViewGroup.MarginLayoutParams mlp = (MarginLayoutParams) mTitleText.getLayoutParams();
      mlp.topMargin = topMargin;
    }
  }
});

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

RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)messageView.getLayoutParams();
int[]rules = params.getRules();
rules[RelativeLayout.RIGHT_OF] = 0;

代码示例来源:origin: akexorcist/Android-RoundCornerProgressBar

private void clearTextProgressAlign() {
  RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tvProgress.getLayoutParams();
  params.addRule(RelativeLayout.ALIGN_LEFT, 0);
  params.addRule(RelativeLayout.ALIGN_RIGHT, 0);
  params.addRule(RelativeLayout.LEFT_OF, 0);
  params.addRule(RelativeLayout.RIGHT_OF, 0);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    params.removeRule(RelativeLayout.START_OF);
    params.removeRule(RelativeLayout.END_OF);
    params.removeRule(RelativeLayout.ALIGN_START);
    params.removeRule(RelativeLayout.ALIGN_END);
  }
  tvProgress.setLayoutParams(params);
}

代码示例来源: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: smuyyh/BookReader

@Override
public void convert(EasyLVHolder holder, int position, String s) {
  holder.setText(R.id.tvMinorItem, s);
  if (current == position) {
    holder.setVisible(R.id.ivMinorChecked, true);
  } else {
    holder.setVisible(R.id.ivMinorChecked, false);
  }
  if (position != 0) { // 子项右移
    TextView textView = holder.getView(R.id.tvMinorItem);
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textView.getLayoutParams();
    params.leftMargin = ScreenUtils.dpToPxInt(25);
    textView.setLayoutParams(params);
  }
}

代码示例来源:origin: seven332/EhViewer

if (gi.pages == 0 || !Settings.getShowGalleryPages()) {
  holder.pages.setText(null);
  RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.simpleLanguage.getLayoutParams();
  lp.addRule(RelativeLayout.LEFT_OF, 0);
  lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
} else {
  holder.pages.setText(Integer.toString(gi.pages) + "P");
  RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.simpleLanguage.getLayoutParams();
  lp.addRule(RelativeLayout.LEFT_OF, R.id.pages);
  lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);

代码示例来源:origin: aurelhubert/ahbottomnavigation

notification.getLayoutParams();
  paramsNotification.setMargins(notificationActiveMarginLeft, paramsNotification.topMargin,
      paramsNotification.rightMargin, paramsNotification.bottomMargin);
icon.setSelected(false);
ViewGroup.MarginLayoutParams paramsNotification = (ViewGroup.MarginLayoutParams)
    notification.getLayoutParams();
paramsNotification.setMargins(notificationInactiveMarginLeft, paramsNotification.topMargin,
    paramsNotification.rightMargin, paramsNotification.bottomMargin);

代码示例来源:origin: aurelhubert/ahbottomnavigation

notification.getLayoutParams();
    paramsNotification.setMargins(notificationActiveMarginLeft, notificationActiveMarginTop,
        paramsNotification.rightMargin, paramsNotification.bottomMargin);
icon.setSelected(false);
ViewGroup.MarginLayoutParams paramsNotification = (ViewGroup.MarginLayoutParams)
    notification.getLayoutParams();
paramsNotification.setMargins(notificationInactiveMarginLeft, notificationInactiveMarginTop,
    paramsNotification.rightMargin, paramsNotification.bottomMargin);

代码示例来源:origin: nanchen2251/RxJava2Examples

@Override
  protected void initView(Bundle savedInstanceState) {
//        StatusBarUtil.setTranslucent(this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // 4.4 以上版本
      // 设置 Toolbar 高度为 80dp,适配状态栏
      ViewGroup.LayoutParams layoutParams = mToolbarTitle.getLayoutParams();
//            layoutParams.height = ScreenUtil.dip2px(this,ScreenUtil.getStatusBarHeight(this));
      layoutParams.height = ScreenUtil.dip2px(this,80);
      mToolbarTitle.setLayoutParams(layoutParams);
    }

    initToolBar(mToolbar, false, "");
    String []titles = {
        GlobalConfig.CATEGORY_NAME_OPERATORS,
        GlobalConfig.CATEGORY_NAME_EXAMPLES
    };

    BaseViewPagerAdapter pagerAdapter = new BaseViewPagerAdapter(getSupportFragmentManager(),titles);
    pagerAdapter.addFragment(new OperatorsFragment());
    pagerAdapter.addFragment(new UseCasesFragment());

    mViewPager.setAdapter(pagerAdapter);
    mTabLayout.setupWithViewPager(mViewPager);
  }

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

title.setTextColor(mBuilder.getTitleTextColor());
title.setTextSize(mBuilder.getTitleTextSize());
LinearLayout.LayoutParams l = (LinearLayout.LayoutParams) title.getLayoutParams();
l.height = UiUtils.dp2px(mContext, mBuilder.getTitleHeight());
title.setLayoutParams(l);

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

.getLayoutParams();
params.height = (int) finalSize * 2;
params.width = (int) finalSize * 2;

相关文章

TextView类方法