TextView自适应大小对于设置TextView的字体默认大小对于UI界面的好看程度是很重要的,小屏幕设置的文字过大或者大屏幕设置的文字过小都造成UI的不美观
现在就让我们学习自适应大小的TextView控件,即当文字长度变化时,文字的大小会相应的变化,保证显示在一行当中
实现依靠于第三方类库 第三方类来源: http://www./android-240301-1-1.html 下载地址: http:///cFs9qKMyFNyfy (提取码:b039) 使用时先导入类库 以eclipse为例 1、File-Import-Android-Existing Android Code Into Workspace 将第三方类库文件导入 2、右键类库 -properties 设置 is Library 3、创建个人项目,添加第三方类库 右键项目-properties-Android-Add 选择类库 OK
然后就是正常的使用TextView了,只需要将要自适应的TextView标签设置为<me.grantland.widget.AutofitTextView/> 注意:一定要设置为单行,否定无法显示效果 android:singleLine="true"
1 <me.grantland.widget.AutofitTextView 2 android:id="@+id/output_autofit" 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content" 5 android:text="@string/example" 6 android:textSize="50sp" 7 android:gravity="center" 8 android:singleLine="true" 9 autofit:minTextSize="8sp" 10 />
布局文件: ![]() string.xml ![]() activity ![]() 效果:
分类: UI美化
|
|