本文整理匯總了Java中android.widget.TextView.getWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java TextView.getWidth方法的具體用法?Java TextView.getWidth怎麽用?Java TextView.getWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.TextView
的用法示例。
在下文中一共展示了TextView.getWidth方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onPostExecute
import android.widget.TextView; //導入方法依賴的package包/類
@Override
protected void onPostExecute(Bitmap result) {
if (result == null) {
return;
}
if (mTextViewRef.get() == null) {
return;
}
TextView textView = mTextViewRef.get();
// change the reference of the current mDrawable to the result
// from the HTTP call
mUrlDrawable.mDrawable = new BitmapDrawable(textView.getResources(), result);
// set bound to scale image to fit width and keep aspect ratio
// according to the result from HTTP call
int width = textView.getWidth();
int height = Math.round(1.0f * width *
mUrlDrawable.mDrawable.getIntrinsicHeight() /
mUrlDrawable.mDrawable.getIntrinsicWidth());
mUrlDrawable.setBounds(0, 0, width, height);
mUrlDrawable.mDrawable.setBounds(0, 0, width, height);
// force redrawing bitmap by setting text
textView.setText(textView.getText());
}
示例2: CsDrawableTouchUtils
import android.widget.TextView; //導入方法依賴的package包/類
CsDrawableTouchUtils(MotionEvent event, TextView view, boolean isLayoutRTL){
this.event = event;
this.view = view;
this.isLayoutRTL = isLayoutRTL;
vSpace = view.getHeight() - view.getCompoundPaddingBottom() - view.getCompoundPaddingTop();
hSpace = view.getWidth() - view.getCompoundPaddingRight() - view.getCompoundPaddingLeft();
//if the drawable is extremely large (pushing the edges of the drawable itself
//or of the other drawables out of the current view bounds, will not be possible
//to calculate the correct touch position
if (hSpace < 0 || vSpace < 0){
throw new IllegalArgumentException("The size of one of your drawable is exceeding the" +
" calculated width or height of the view. In this case you should provide" +
"a smaller drawable or provide a smaller dimension in XML or with the builder");
}
scrollX = view.getScrollX();
scrollY = view.getScrollY();
}
示例3: captureTextBitmap
import android.widget.TextView; //導入方法依賴的package包/類
private static Bitmap captureTextBitmap(TextView textView) {
Drawable background = textView.getBackground();
textView.setBackground(null);
int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight();
int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom();
if (width == 0 || height == 0) {
return null;
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop());
textView.draw(canvas);
textView.setBackground(background);
return bitmap;
}
示例4: TextResizeData
import android.widget.TextView; //導入方法依賴的package包/類
public TextResizeData(TextView textView) {
this.paddingLeft = textView.getPaddingLeft();
this.paddingTop = textView.getPaddingTop();
this.paddingRight = textView.getPaddingRight();
this.paddingBottom = textView.getPaddingBottom();
this.width = textView.getWidth();
this.height = textView.getHeight();
this.gravity = textView.getGravity();
this.textColor = textView.getCurrentTextColor();
}
示例5: ellipsize
import android.widget.TextView; //導入方法依賴的package包/類
public static CharSequence ellipsize(@Nullable CharSequence text, @NonNull TextView view) {
if (TextUtils.isEmpty(text) || view.getWidth() == 0 || view.getEllipsize() != TruncateAt.END) {
return text;
} else {
return TextUtils.ellipsize(text,
view.getPaint(),
view.getWidth() - view.getPaddingRight() - view.getPaddingLeft(),
TruncateAt.END);
}
}
示例6: getRealWidth
import android.widget.TextView; //導入方法依賴的package包/類
private int getRealWidth() {
TextView tv = textViewWeakReference.get();
if (tv == null) {
return 0;
}
return tv.getWidth() - tv.getPaddingRight() - tv.getPaddingLeft();
}
示例7: setScale
import android.widget.TextView; //導入方法依賴的package包/類
public void setScale(float scale){
if(this.scale != scale){
this.scale = scale;
int width;
TextView textView;
for (int i = 0;i < mTextViewList.size();i++){
textView = mTextViewList.get(i);
width = textView.getWidth();
textView.setWidth((int) (width * (1 + scale)));
widthList.set(i, (int) (width * (1 + scale)));
}
}
}
示例8: adjustViewDirection
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Adjusts the given {@code TextView} to have a layout direction that matches the UI direction
* when the contents of the view is considered short (based on SHORTNESS_FACTOR).
* @param textView The text view to adjust.
*/
@SuppressLint("RtlHardcoded")
private void adjustViewDirection(TextView textView) {
float textWidth = textView.getPaint().measureText(textView.getText().toString());
if (textWidth < SHORTNESS_FACTOR * textView.getWidth()) {
int layoutDirection =
LocalizationUtils.isLayoutRtl() ? LayoutDirection.RTL : LayoutDirection.LTR;
if (layoutDirection == LayoutDirection.LTR) textView.setGravity(Gravity.LEFT);
if (layoutDirection == LayoutDirection.RTL) textView.setGravity(Gravity.RIGHT);
}
}
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:16,代碼來源:OverlayPanelTextViewInflater.java
示例9: resizeText
import android.widget.TextView; //導入方法依賴的package包/類
public static void resizeText(TextView textView, int originalTextSize, int minTextSize) {
final Paint paint = textView.getPaint();
final int width = textView.getWidth();
if (width == 0) {
return;
}
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalTextSize);
float ratio = width / paint.measureText(textView.getText().toString());
if (ratio <= 1.0f) {
textView.setTextSize(
TypedValue.COMPLEX_UNIT_PX, Math.max(minTextSize, originalTextSize * ratio));
}
}
示例10: layoutImportantNotice
import android.widget.TextView; //導入方法依賴的package包/類
public void layoutImportantNotice(final View importantNoticeStrip,
final String importantNoticeTitle) {
final TextView titleView = (TextView)importantNoticeStrip.findViewById(
R.id.important_notice_title);
final int width = titleView.getWidth() - titleView.getPaddingLeft()
- titleView.getPaddingRight();
titleView.setTextColor(mColorAutoCorrect);
titleView.setText(importantNoticeTitle); // TextView.setText() resets text scale x to 1.0.
final float titleScaleX = getTextScaleX(importantNoticeTitle, width, titleView.getPaint());
titleView.setTextScaleX(titleScaleX);
}
示例11: autofit
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
*/
private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize,
int maxLines, float precision) {
if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
// Don't auto-size since there's no limit on lines.
return;
}
int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (targetWidth <= 0) {
return;
}
CharSequence text = view.getText();
TransformationMethod method = view.getTransformationMethod();
if (method != null) {
text = method.getTransformation(text, view);
}
Context context = view.getContext();
Resources r = Resources.getSystem();
DisplayMetrics displayMetrics;
float size = maxTextSize;
float high = size;
float low = 0;
if (context != null) {
r = context.getResources();
}
displayMetrics = r.getDisplayMetrics();
paint.set(view.getPaint());
paint.setTextSize(size);
if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
|| getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
displayMetrics);
}
if (size < minTextSize) {
size = minTextSize;
}
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
示例12: adjustSize
import android.widget.TextView; //導入方法依賴的package包/類
/**
* 改變外框大小,適應文字
* 如果當前文字隻有一行,則縮到外框適應文字大小
* 如果文字有多行,則寬度不變,縮小高度到適應文字大小
* 文字外框的位置不變
*
* @param view
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void adjustSize(TextView view) {
if (view != null && view.getLayoutParams() != null) {
/*
//更好的實現方式,但是ios那邊不支持這種方式
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
view.setLayoutParams(layoutParams);*/
// 廢棄的實現方式,使用WRAP_CONTENT最簡單,且這種方式算出來的width有bug
// @Deprecated
/*int lineCount = Math.min(view.getLineCount(), getMaxLines(view));
int width, height;
if (lineCount > 1) {//多行,寬度不變,改變高度
width = view.getWidth();
height = view.getLineHeight() * lineCount + view.getPaddingTop() + view.getPaddingBottom();
} else {//一行,改變寬度&高度
final Paint paint = view.getPaint();
width = (int) paint.measureText(view.getText().toString()) + view.getPaddingLeft() + view.getPaddingRight();
height = view.getLineHeight() + view.getPaddingTop() + view.getPaddingBottom();
}*/
int lineCount = Math.min(view.getLineCount(), getMaxLines(view));
float width, height;
if (lineCount > 1) {//多行,寬度不變,改變高度
width = view.getWidth();
height = view.getLineHeight() * lineCount + view.getPaddingTop() + view.getPaddingBottom();
} else {//一行,改變寬度&高度
width = view.getPaddingLeft() + Layout.getDesiredWidth(view.getText(), view.getPaint()) + view.getPaddingRight();
height = view.getLineHeight() + view.getPaddingTop() + view.getPaddingBottom();
}
if (view.getLayoutParams() != null) {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.width = (int) width;
layoutParams.height = (int) height;
view.setLayoutParams(layoutParams);
}
}
}
示例13: adjustTextSize
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
*/
private static void adjustTextSize(TextView view, TextPaint paint, float minTextSize, float maxTextSize, int maxLines, float precision) {
if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
// Don't auto-size since there's no limit on lines.
return;
}
int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (targetWidth <= 0) {
return;
}
CharSequence text = view.getText();
TransformationMethod method = view.getTransformationMethod();
if (method != null) {
text = method.getTransformation(text, view);
}
Context context = view.getContext();
Resources r = Resources.getSystem();
DisplayMetrics displayMetrics;
float size = maxTextSize;
float high = size;
float low = 0;
if (context != null) {
r = context.getResources();
}
displayMetrics = r.getDisplayMetrics();
paint.set(view.getPaint());
paint.setTextSize(size);
if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
|| getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision, displayMetrics);
}
if (size < minTextSize) {
size = minTextSize;
}
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
示例14: autofit
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
*/
private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize,
int maxLines, float precision) {
if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
// Don't auto-size since there's no limit on lines.
return;
}
int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (targetWidth <= 0) {
return;
}
CharSequence text = view.getText();
TransformationMethod method = view.getTransformationMethod();
if (method != null) {
text = method.getTransformation(text, view);
}
Context context = view.getContext();
Resources r = Resources.getSystem();
DisplayMetrics displayMetrics;
float size = maxTextSize;
float high = size;
float low = 0;
if (context != null) {
r = context.getResources();
}
displayMetrics = r.getDisplayMetrics();
paint.set(view.getPaint());
paint.setTextSize(size);
if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
|| getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
displayMetrics);
}
if (size < minTextSize) {
size = minTextSize;
}
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}