/**
* Re size the font so the specified text fits in the text box assuming the text box is the
* specified width.
*/
private void refitText() {
if (!mSizeToFit) {
return;
}
if (mMaxLines <= 0) {
// Don't auto-size since there's no limit on lines.
return;
}
CharSequence text = getText();
TransformationMethod method = getTransformationMethod();
if (method != null) {
text = method.getTransformation(text, this);
}
int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight();
if (targetWidth > 0) {
Context context = getContext();
Resources r = Resources.getSystem();
DisplayMetrics displayMetrics;
float size = mMaxTextSize;
float high = size;
float low = 0;
if (context != null) {
r = context.getResources();
}
displayMetrics = r.getDisplayMetrics();
mPaint.set(getPaint());
mPaint.setTextSize(size);
if ((mMaxLines == 1 && mPaint.measureText(text, 0, text.length()) > targetWidth)
|| getLineCount(text, mPaint, size, targetWidth, displayMetrics) > mMaxLines) {
size = getTextSize(text, mPaint, targetWidth, mMaxLines, low, high, mPrecision,
displayMetrics);
}
if (size < mMinTextSize) {
size = mMinTextSize;
}
super.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
}
AutofitTextView.java 文件源码
java
阅读 19
收藏 0
点赞 0
评论 0
项目:UltimateAndroid
作者:
评论列表
文章目录