代码如下 | 复制代码 |
/** * 自定义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()); } } |
樱花校园模拟器4399中文版
樱花校园模拟器4399中文版,十分奇趣好玩的3d校园冒险模拟
我的暑假秘密回忆繁星新春版
我的暑假秘密回忆繁星新春版是一款少女模拟养成类休闲游戏。这款
樱花校园模拟器国际版
樱花校园模拟器国际版,一个超级自由超级好玩的自由恋爱模拟的游
饥荒海难九游版
饥荒海难九游版,带你去真实的海岛上感受一下什么才是真正的孤岛
盖瑞模组体验版最新版
盖瑞模组体验版是玩法非常丰富多元化的沙盒建造游戏,玩家可以在