代码如下 | 复制代码 |
/** * 自定义TextView,文本内容自动调整字体大小以适应TextView的大小 * @author yzp */ publicclassAutoFitTextViewextendsTextView { privatePaint mTextPaint; privatefloatmTextSize; publicAutoFitTextView(Context context) { super(context); } publicAutoFitTextView(Context context, AttributeSet attrs) { super(context, attrs); } /** * Re size the font so the specified text fits in the text box assuming the * text box is the specified width. * * @param text * @param textWidth */ privatevoidrefitText(String text,inttextViewWidth) { if(text ==null|| textViewWidth <=0) return; mTextPaint =newPaint(); mTextPaint.set(this.getPaint()); intavailableTextViewWidth = getWidth() - getPaddingLeft() - getPaddingRight(); float[] charsWidthArr =newfloat[text.length()]; Rect boundsRect =newRect(); mTextPaint.getTextBounds(text,0, text.length(), boundsRect); inttextWidth = boundsRect.width(); mTextSize = getTextSize(); while(textWidth > availableTextViewWidth) { mTextSize -=1; mTextPaint.setTextSize(mTextSize); textWidth = mTextPaint.getTextWidths(text, charsWidthArr); } this.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); } @Override protectedvoidonDraw(Canvas canvas) { super.onDraw(canvas); refitText(this.getText().toString(),this.getWidth()); } } |
凡尔赛法环免广告版 最新版v1.69.1
下载天煞异种 安卓版v1.0.21
下载十三月 (Undecember)最新官方中文版v3.26.0200
下载我不是废柴无限99999钻999999金币游戏 不减反增版v1.2.16
下载我的女友是声优免广告 安卓版v1
我的女友是声优免广告是一款非常好玩的模拟经营类手游,玩家在游
石器帝国去广告版 v8
石器帝国免广告版是游戏的破解版本,在该版本中为玩家去除了广告
校园恋爱模拟器真人版去广告版 v0.0.7
校园恋爱模拟器真人版免广告版是游戏的破解版本,在该版本中为玩
教练我要开球馆内置菜单修改器 安卓版v1.5.4
教练我要开球馆内购版是一款模拟经营类游戏,玩家们将在游戏中创
我的游轮无限砖石 安卓版v1.7.0
我的游轮无限金币钻石版是一款模拟经营类游戏,你将成为一艘游轮