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

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

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

TextView.setMaxWidth介绍

暂无

代码示例

代码示例来源:origin: TheFinestArtist/FinestWebView-Android

protected void requestCenterLayout() {
 int maxWidth;
 if (webView.canGoBack() || webView.canGoForward()) {
  maxWidth = DisplayUtil.getWidth() - UnitConverter.dpToPx(48) * 4;
 } else {
  maxWidth = DisplayUtil.getWidth() - UnitConverter.dpToPx(48) * 2;
 }
 title.setMaxWidth(maxWidth);
 urlTv.setMaxWidth(maxWidth);
 title.requestLayout();
 urlTv.requestLayout();
}

代码示例来源:origin: rey5137/material

v.setMaxWidth(a.getDimensionPixelSize(attr, -1));

代码示例来源:origin: TheFinestArtist/FinestWebView-Android

title.setMaxWidth(maxWidth);
urlTv.setMaxWidth(maxWidth);
requestCenterLayout();

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

//Add to oncreate in your Activity

   private TextView textStatus;   
   textStatus = (TextView) findViewById(R.id.TextForWhiteBox); 

// This get's the width of your display.
DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int width = displaymetrics.widthPixels;

// Now you know the screen orientation, and it's width. So just set the maxwidth of the text view to match the display width - the pixels of your white box. 

   textStatus.setMaxWidth(width - 32); // 32 is here because you already know the size of the white box. More logic is needed to dynamically get this value, because you would need to wait for the activity to be fully created.
}

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

final TextView textView = (TextView)findViewById(R.id.text);
 textView.setSingleLine();
 textView.animate()
     .translationX(dip2px(MainActivity.this, -100))
     .setDuration(200)
     .setInterpolator(new AccelerateDecelerateInterpolator())
     .setStartDelay(2000)
     .start();
 ValueAnimator anim= ValueAnimator.ofInt(textView.getMaxWidth(),textView.getMaxWidth()+ dip2px(MainActivity.this, 200));
 anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
   @Override
   public void onAnimationUpdate(ValueAnimator animation) {
     int value = (int) animation.getAnimatedValue();
     textView.setMaxWidth(value);
   }
 });
 anim.setDuration(200);
 anim.setStartDelay(2000);
 anim.start();

代码示例来源:origin: Tencent/RapidView

public void run(RapidParserObject object, Object view, Var value) {
    int width = 0;
    String str = value.getString();
    if( str.length() >= 1 && str.substring(str.length() - 1).compareToIgnoreCase("%") == 0 ){
      float percent = Float.parseFloat(str.substring(0, str.length() - 1)) / 100;
      width = (int)(percent * object.mScreenWidth);
    }
    else if( str.length() >= 2 && str.substring(str.length() - 2).compareToIgnoreCase("%x") == 0 ){
      float percent = Float.parseFloat(str.substring(0, str.length() - 2)) / 100;
      width = (int)(percent * object.mScreenWidth);
    }
    else if( str.length() >= 2 && str.substring(str.length() - 2).compareToIgnoreCase("%y") == 0 ){
      float percent = Float.parseFloat(str.substring(0, str.length() - 2)) / 100;
      width = (int)(percent * object.mScreenHeight);
    }
    else{
      width = ViewUtils.dip2px(object.mContext, value.getFloat());
    }
    ((TextView)view).setMaxWidth(width);
  }
}

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

final TextView tvLeft = (TextView) findViewById(R.id.ns_txt);
final TextView tvRight = (TextView) findViewById(R.id.ns_in_txt);
ViewTreeObserver obs = tvRight.getViewTreeObserver();
obs.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
      @Override
  public void onGlobalLayout() {
    tvLeft.setMaxWidth(SCREEN_WIDTH - tvRight.getWidth());
  }
});

代码示例来源:origin: xiangzhihong/gpuImage

private void init() {
  this.paint = new Paint();
  this.paint.setColor(-1);
  this.paint.setAntiAlias(true);
  this.paint.setStyle(Paint.Style.FILL);
  this.paint.setTextSize(12.0F);
  this.paint.setStrokeWidth(1.0F);
  for (int i = 0; i < 8; i++) {
    MarginLayoutParams localMarginLayoutParams = new MarginLayoutParams(-2, -2);
    this.tags[i] = new TextView(getContext());
    this.tags[i].setTextSize(12.0F);
    this.tags[i].setShadowLayer(1.6F * getResources().getDisplayMetrics().density, 0.0F, 0.0F, Color.argb(204, 0, 0, 0));
    this.tags[i].setTextColor(-1);
    this.tags[i].setSingleLine();
    this.tags[i].setMaxWidth(screenW / 2 - dis-20);
    this.tags[i].setPadding(12, 4, 12, 4);
    this.tags[i].setCompoundDrawablePadding(4);
    this.tags[i].setTag(Integer.valueOf(i));
    this.tags[i].setVisibility(INVISIBLE);
    addView(this.tags[i], localMarginLayoutParams);
  }
}

代码示例来源:origin: bitstadium/HockeySDK-Android

private void configureViewForPlaceholder(final boolean openOnClick) {
  mTextView.setMaxWidth(mWidthPortrait);
  mTextView.setMinWidth(mWidthPortrait);
  mImageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams
      .WRAP_CONTENT));
  mImageView.setAdjustViewBounds(false);
  mImageView.setBackgroundColor(Color.parseColor("#eeeeee"));
  mImageView.setMinimumHeight((int) (mWidthPortrait * 1.2f));
  mImageView.setMinimumWidth(mWidthPortrait);
  mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
  mImageView.setImageDrawable(getSystemIcon("ic_menu_attachment"));
  mImageView.setContentDescription(mTextView.getText());
  mImageView.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
      if (!openOnClick) {
        return;
      }
      Intent intent = new Intent();
      intent.setAction(Intent.ACTION_VIEW);
      intent.setDataAndType(mAttachmentUri, "*/*");
      mContext.startActivity(intent);
    }
  });
}

代码示例来源:origin: mabbas007/TagsEditText

private TextView createTextView(String text) {
  TextView textView = new TextView(getContext());
  if (getWidth() > 0) {
    textView.setMaxWidth(getWidth() - 50);
  }
  textView.setText(text);
  textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTagsTextSize);
  textView.setTextColor(mTagsTextColor);
  textView.setPadding(mTagsPaddingLeft, mTagsPaddingTop, mTagsPaddingRight, mTagsPaddingBottom);
  // check Android version for set background
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    textView.setBackground(mTagsBackground);
  } else {
    textView.setBackgroundDrawable(mTagsBackground);
  }
  textView.setCompoundDrawablesWithIntrinsicBounds(mLeftDrawable, null, mRightDrawable, null);
  textView.setCompoundDrawablePadding(mDrawablePadding);
  return textView;
}

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

private static Bitmap renderTextIntoBitmap(Context context, Bitmap.Config bitmapConfig, String text, int textColor, int maxTextWidth) {
  LayoutInflater inflater = LayoutInflater.from(context);
  TextView tv = (TextView) inflater.inflate(R.layout.just_a_textview, null);
  tv.setText(text);
  tv.setMaxWidth(maxTextWidth);

  int widthSpec = View.MeasureSpec.makeMeasureSpec(maxTextWidth, View.MeasureSpec.EXACTLY);
  int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);

  tv.measure(widthSpec, heightSpec);
  tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());
  tv.setTextColor(textColor);

  Bitmap bitmap = Bitmap.createBitmap(tv.getWidth(), tv.getHeight(), bitmapConfig);
  Canvas canvas = new Canvas(bitmap);
  tv.draw(canvas);
  return bitmap;
}

代码示例来源:origin: bitstadium/HockeySDK-Android

private void configureViewForThumbnail(Bitmap bitmap, final boolean openOnClick) {
  int width = mOrientation == ImageUtils.ORIENTATION_LANDSCAPE ? mWidthLandscape : mWidthPortrait;
  int height = mOrientation == ImageUtils.ORIENTATION_LANDSCAPE ? mMaxHeightLandscape :
      mMaxHeightPortrait;
  mTextView.setMaxWidth(width);
  mTextView.setMinWidth(width);
  mImageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams
      .WRAP_CONTENT));
  mImageView.setAdjustViewBounds(true);
  mImageView.setMinimumWidth(width);
  mImageView.setMaxWidth(width);
  mImageView.setMaxHeight(height);
  mImageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
  mImageView.setImageBitmap(bitmap);
  mImageView.setContentDescription(mTextView.getText());
  mImageView.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
      if (!openOnClick) {
        return;
      }
      Intent intent = new Intent();
      intent.setAction(Intent.ACTION_VIEW);
      intent.setDataAndType(mAttachmentUri, "image/*");
      mContext.startActivity(intent);
    }
  });
}

代码示例来源:origin: cattaka/LearnAnimation

@Override
  public void onClick(View view) {
    if (view.getId() == R.id.button_hide) {
      int from = mLabelText.getWidth();
      int to = 0;
      ObjectAnimator.ofInt(mLabelText, "width", from, to).start();
    } else if (view.getId() == R.id.button_show) {
      int from = mLabelText.getWidth();
      mLabelText.setMaxWidth(Integer.MAX_VALUE);
      mLabelText.setMaxHeight(Integer.MAX_VALUE);
      mLabelText.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      int to = mLabelText.getMeasuredWidth();
      ObjectAnimator.ofInt(mLabelText, "width", from, to).start();
    }
  }
}

代码示例来源:origin: QuickBlox/ChatMessagesAdapter-android

protected void fillTextMessageHolder(TextMessageHolder holder, T chatMessage, int position, boolean isLeftMessage) {
  holder.linkPreviewLayout.setVisibility(View.GONE);
  holder.messageTextView.setText(chatMessage.getBody());
  holder.timeTextMessageTextView.setText(getDate(chatMessage.getDateSent()));
  setMessageTextViewLinkClickListener(holder, position);
  int valueType = getItemViewType(position);
  String avatarUrl = obtainAvatarUrl(valueType, chatMessage);
  if (avatarUrl != null) {
    displayAvatarImage(avatarUrl, holder.avatar);
  }
  final List<String> urlsList = LinkUtils.extractUrls(chatMessage.getBody());
  if (!urlsList.isEmpty()) {
    holder.messageTextView.setMaxWidth((int) context.getResources().getDimension(R.dimen.link_preview_width));
    holder.linkPreviewLayout.setTag(chatMessage.getId());
    if (isLeftMessage) {
      processLinksFromLeftMessage(holder, urlsList, position);
    } else {
      processLinksFromRightMessage(holder, urlsList, position);
    }
  } else {
    holder.messageTextView.setMaxWidth(context.getResources().getDisplayMetrics().widthPixels);
  }
}

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

measureView(rightText);
leftText.setMaxWidth(getWidth() - rightText.getMeasuredWidth());

代码示例来源:origin: huangweicai/OkLibDemo

private TextView createCenterTitle() {
  TextView centerTitleTv = new TextView(getContext());
  centerTitleTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
  centerTitleTv.setTextColor(getResources().getColor(R.color.oklib_frame_black));
  LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
  params.gravity = Gravity.CENTER;//layout_gravity
  centerTitleTv.setLayoutParams(params);
  //单行并长度显示处理
  centerTitleTv.setFocusable(true);
  centerTitleTv.setFocusableInTouchMode(true);
  centerTitleTv.setSingleLine();
  centerTitleTv.setEllipsize(TextUtils.TruncateAt.END);
  //控制最大长度
  centerTitleTv.setMaxWidth(getScreenWidth(getContext()) - dp2px(getContext(), 130));
  return centerTitleTv;
}

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

private void setTabsMaxWidth() {
  DisplayMetrics displaymetrics = new DisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
  int screenWidth = displaymetrics.widthPixels;
  final ActionBar actionBar = getActionBar();
  final View tabView = actionBar.getTabAt(0).getCustomView();
  final View tabContainerView = (View) tabView.getParent();
  final int tabPadding = tabContainerView.getPaddingLeft() + tabContainerView.getPaddingRight();
  final int tabs = actionBar.getTabCount();
  for(int i=0 ; i < tabs ; i++) {
   View tab = actionBar.getTabAt(i).getCustomView();
   TextView text1 = (TextView) tab.findViewById(R.id.text1);
   text1.setMaxWidth(screenWidth/tabs-tabPadding-1);
 }
}

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

private void setTabsMaxWidth() {
  DisplayMetrics displaymetrics = new DisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
  int screenWidth = displaymetrics.widthPixels;
  final ActionBar actionBar = getActionBar();
  final View tabView = actionBar.getTabAt(0).getCustomView();
  final View tabContainerView = (View) tabView.getParent();
  final int tabPadding = tabContainerView.getPaddingLeft() + tabContainerView.getPaddingRight();
  final int tabs = actionBar.getTabCount();
  for(int i=0 ; i < tabs ; i++) {
   View tab = actionBar.getTabAt(i).getCustomView();
   TextView text1 = (TextView) tab.findViewById(R.id.text1);
   text1.setMaxWidth(screenWidth/tabs-tabPadding-1);
 }
}

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

private void setTabsMaxWidth() {
  DisplayMetrics displaymetrics = new DisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
  int screenWidth = displaymetrics.widthPixels;
  final ActionBar actionBar = getActionBar();
  final View tabView = actionBar.getTabAt(0).getCustomView();
  final View tabContainerView = (View) tabView.getParent();
  final int tabPadding = tabContainerView.getPaddingLeft() + tabContainerView.getPaddingRight();
  final int tabs = actionBar.getTabCount();
  for(int i=0 ; i < tabs ; i++){
    View tab = actionBar.getTabAt(i).getCustomView();
    TextView text1 = (TextView) tab.findViewById(R.id.text1);
    text1.setMaxWidth(screenWidth/tabs-tabPadding-1);
  }
}

代码示例来源:origin: easefun/polyv-android-sdk-2.0-demo

tv_context.setMaxWidth(((ViewGroup) getParent()).getWidth() * 3 / 4);//调整最大的宽度,不然iv_seek可能会显示不了
tv_context.setText(videokeyframe.getKeycontext());
tv_context.post(runnable = new Runnable() {

相关文章

TextView类方法