http://www.cnblogs.com/psuwgipgf/p/4874158.html
一、 TextView字体随大小变化自适应TextView
实现依靠于第三方类库
第三方类来源:
http://www.apkbus.com/android-240301-1-1.html
下载地址:
http://yunpan.cn/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 <?xml version="1.0" encoding="utf-8"?> 2 <ScrollView xmlns:andro 3 xmlns:autofit="http://schemas.android.com/apk/res-auto" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent"> 6 <LinearLayout 7 android:layout_width="match_parent" 8 android:layout_height="wrap_content" 9 android:orientation="vertical" 10 > 11 <EditText 12 android: 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" 15 android:singleLine="true" 16 android:hint="@string/input_hint" 17 android:text="@string/example"/> 18 <TextView 19 android:layout_width="match_parent" 20 android:layout_height="wrap_content" 21 android:text="@string/label_normal" 22 /> 23 <TextView 24 android: 25 android:layout_width="match_parent" 26 android:layout_height="wrap_content" 27 android:text="@string/example" 28 android:textSize="50sp" 29 android:gravity="center" 30 /> 31 <TextView 32 android:layout_width="match_parent" 33 android:layout_height="wrap_content" 34 android:text="@string/label_autofit" 35 /> 36 <me.grantland.widget.AutofitTextView 37 android: 38 android:layout_width="match_parent" 39 android:layout_height="wrap_content" 40 android:text="@string/example" 41 android:textSize="50sp" 42 android:gravity="center" 43 android:singleLine="true" 44 autofit:minTextSize="8sp" 45 /> 46 </LinearLayout> 47 </ScrollView> 48 49 activity_main.xml