本文整理匯總了Java中android.widget.TextView.getMeasuredWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java TextView.getMeasuredWidth方法的具體用法?Java TextView.getMeasuredWidth怎麽用?Java TextView.getMeasuredWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.TextView
的用法示例。
在下文中一共展示了TextView.getMeasuredWidth方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drawLabels
import android.widget.TextView; //導入方法依賴的package包/類
private void drawLabels() {
List<Float> indicatorPosition = mStepsViewIndicator.getThumbContainerXPosition();
if (mLabels != null) {
for (int i = 0; i < mLabels.length; i++) {
TextView textView = new TextView(getContext());
textView.setText(mLabels[i]);
textView.setTextColor(mLabelColorIndicator);
textView.setTextSize(mLabelTextSize);
textView.setGravity(Gravity.CENTER);
textView.setLayoutParams(
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
textView.measure(0, 0);
float textWidth = textView.getMeasuredWidth();
textView.setX(indicatorPosition.get(i) - (textWidth / 2));
mLabelsLayout.addView(textView);
}
}
}
示例2: setMdText
import android.widget.TextView; //導入方法依賴的package包/類
public static void setMdText(@NonNull TextView textView, String markdown) {
if (!InputHelper.isEmpty(markdown)) {
int width = textView.getMeasuredWidth();
if (width > 0) {
render(textView, markdown, width);
} else {
textView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override public boolean onPreDraw() {
textView.getViewTreeObserver().removeOnPreDrawListener(this);
render(textView, markdown, textView.getMeasuredWidth());
return true;
}
});
}
}
}
示例3: createLabelBitmap
import android.widget.TextView; //導入方法依賴的package包/類
public Bitmap createLabelBitmap(String label) {
if (DBG) Log.d(TAG, "createLabelBitmap : label="+ label);
mLabelView = (TextView)mLayoutInflater.inflate(R.layout.cover_roll_label, null);
mLabelView.setText(label);
mLabelView.setLayoutParams( new FrameLayout.LayoutParams(NO_SIZE_LIMIT,NO_SIZE_LIMIT) );
mLabelView.measure(NO_SIZE_LIMIT, NO_SIZE_LIMIT);
final int width = mLabelView.getMeasuredWidth();
final int height = mLabelView.getMeasuredHeight();
if(DBG) Log.d(TAG, "createLabelBitmap: mLabelView size = "+width+"x"+height);
mLabelView.layout(0, 0, width, height);
StaticLayout textLayout = null;
if (isRtlLabel()) {
// Archos hack : when a right-to-left language is selected calling TextView.draw()
// draws the background but not the text, so also call TextLayout.draw() which works
textLayout = createTextLayout(label, Color.LTGRAY, mContentLabelFontsize, width);
}
return createViewBitmap(mLabelView, textLayout, width, height, ALIGN_BOTTOM);
}
示例4: showInfoGame
import android.widget.TextView; //導入方法依賴的package包/類
public void showInfoGame(GridView layout) {
int colWidth = 0;
if (getCount() > 0) {
// Use the first item to measure the column width
TextView tempView = createTextView(getItem(0));
tempView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
tempView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
colWidth = tempView.getMeasuredWidth();
}
layout.setColumnWidth(colWidth);
layout.requestLayout();
}
示例5: measureNumColumns
import android.widget.TextView; //導入方法依賴的package包/類
private int measureNumColumns(ViewGroup layout, CharSequence item, CharSequence title) {
int colWidth = 0;
int viewWidth = 0;
if (getSize() > 0) {
// Use the first item to measure the column width
TextView tempView = createTextView(item);
tempView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
tempView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
colWidth = tempView.getMeasuredWidth() + 4;
// Stack overflow when called just after resized layout !?
viewWidth = layout.getWidth();
// If table layout not inflated yet, use device width
if (viewWidth <= 0) {
viewWidth = mRes.getDisplayMetrics().widthPixels - 2 * mRes.getDimensionPixelOffset(R.dimen.activity_horizontal_margin);
}
if (title != null) {
tempView = createTextView(title);
tempView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
tempView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
viewWidth -= tempView.getMeasuredWidth();
}
}
if (colWidth != 0) {
return Math.max(1, viewWidth/colWidth);
} else {
return 1;
}
}
示例6: MeasureString
import android.widget.TextView; //導入方法依賴的package包/類
public static Point MeasureString(Context context, String text, float fontSize, int widthMeasureSpec, int heightMeasureSpec) {
int width = 0;
int height = 0;
if (null == context || null == text || text.isEmpty() || 0 == fontSize) {
return null;
}
TextView tv = new TextView(context);
tv.setText(text);// 待測文本
tv.setTextSize(fontSize);// 字體
if (ViewGroup.LayoutParams.WRAP_CONTENT != widthMeasureSpec && ViewGroup.LayoutParams.MATCH_PARENT != widthMeasureSpec) {
tv.setWidth(widthMeasureSpec);// 如果設置了寬度,字符串的寬度則為所設置的寬度
}
if (ViewGroup.LayoutParams.WRAP_CONTENT != heightMeasureSpec && ViewGroup.LayoutParams.MATCH_PARENT != heightMeasureSpec) {
tv.setHeight(heightMeasureSpec);
}
tv.setSingleLine(false);// 多行
tv.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
width = tv.getMeasuredWidth();
height = tv.getMeasuredHeight();
Point point = new Point();
point.x = width;
point.y = height;
return point;
}
示例7: getMeasuredWidth
import android.widget.TextView; //導入方法依賴的package包/類
private int getMeasuredWidth(@NonNull Context context) {
DisplayMetrics metrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
int maxWidth = context.getResources().getDimensionPixelSize(R.dimen.tooltip_max_width);
int minWidth = context.getResources().getDimensionPixelSize(R.dimen.tooltip_min_width);
String longestText = mBuilder.mContent;
if (mBuilder.mContent.length() < mBuilder.mDesc.length()) {
longestText = mBuilder.mDesc;
}
int padding = context.getResources().getDimensionPixelSize(R.dimen.content_margin);
TextView textView = new TextView(context);
textView.setPadding(padding, 0, padding, 0);
textView.setTypeface(TypefaceHelper.getRegular(context));
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources()
.getDimension(R.dimen.text_content_subtitle));
textView.setText(longestText);
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(metrics.widthPixels, View.MeasureSpec.AT_MOST);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
textView.measure(widthMeasureSpec, heightMeasureSpec);
int measuredWidth = textView.getMeasuredWidth() + padding;
if (measuredWidth <= minWidth) {
return minWidth;
}
if (measuredWidth >= minWidth && measuredWidth <= maxWidth) {
return measuredWidth;
}
return maxWidth;
}
示例8: getMeasuredWidth
import android.widget.TextView; //導入方法依賴的package包/類
private int getMeasuredWidth(@NonNull Context context) {
DisplayMetrics metrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
int maxWidth = context.getResources().getDimensionPixelSize(R.dimen.popup_max_width);
int minWidth = context.getResources().getDimensionPixelSize(R.dimen.popup_min_width);
String longestText = "";
for (PopupItem item : mAdapter.getItems()) {
if (item.getTitle().length() > longestText.length())
longestText = item.getTitle();
}
int padding = context.getResources().getDimensionPixelSize(R.dimen.content_margin);
int iconSize = context.getResources().getDimensionPixelSize(R.dimen.icon_size_small);
TextView textView = new TextView(context);
textView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
textView.setTypeface(TypefaceHelper.getRegular(context));
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources()
.getDimension(R.dimen.text_content_subtitle));
textView.setPadding(padding + iconSize + padding, 0, padding, 0);
textView.setText(longestText);
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(metrics.widthPixels, View.MeasureSpec.AT_MOST);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
textView.measure(widthMeasureSpec, heightMeasureSpec);
int measuredWidth = textView.getMeasuredWidth() + padding;
if (measuredWidth <= minWidth) {
return minWidth;
}
if (measuredWidth >= minWidth && measuredWidth <= maxWidth) {
return measuredWidth;
}
return maxWidth;
}
示例9: layoutDebugInfo
import android.widget.TextView; //導入方法依賴的package包/類
private void layoutDebugInfo(final int positionInStrip, final ViewGroup placerView,
final int x) {
final TextView debugInfoView = mDebugInfoViews.get(positionInStrip);
final CharSequence debugInfo = debugInfoView.getText();
if (debugInfo == null) {
return;
}
placerView.addView(debugInfoView);
debugInfoView.measure(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final int infoWidth = debugInfoView.getMeasuredWidth();
final int y = debugInfoView.getMeasuredHeight();
ViewLayoutUtils.placeViewAt(
debugInfoView, x - infoWidth, y, infoWidth, debugInfoView.getMeasuredHeight());
}
示例10: ensureMinimumTextWidth
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Ensures that a TextView is wide enough to contain its text without
* wrapping or clipping. Measures the specified view and sets the minimum
* width to the view's desired width.
*
* @param v the text view to measure
*/
private static void ensureMinimumTextWidth(TextView v) {
v.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
// Set both the TextView and the View version of minimum
// width because they are subtly different.
final int minWidth = v.getMeasuredWidth();
v.setMinWidth(minWidth);
v.setMinimumWidth(minWidth);
}