TextView UI美化-------自适应字体控件
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"
布局文件中的属性 布局文件
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:autofit="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="@string/input_hint"
android:text="@string/example"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/label_normal"
/>
<TextView
android:id="@+id/output"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/example"
android:textSize="50sp"
android:gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/label_autofit"
/>
<me.grantland.widget.AutofitTextView
android:id="@+id/output_autofit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/example"
android:textSize="50sp"
android:gravity="center"
android:singleLine="true"
autofit:minTextSize="8sp"
/>
</LinearLayout>
</ScrollView> activity_main.xml
activity_main
String.xml
<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">Texttest</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string> <string name="input_hint">text</string>
<string name="label_normal">Normal:</string>
<string name="label_autofit">Autofit:</string> <string name="example">This is an example</string> </resources>
String.xml
activity
package com.example.texttest; import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.widget.EditText;
import android.widget.TextView; public class MainActivity extends Activity { private TextView mOutput;
private TextView mAutofitOutput;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mOutput = (TextView)findViewById(R.id.output);
mAutofitOutput = (TextView)findViewById(R.id.output_autofit); ((EditText)findViewById(R.id.input)).addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
// do nothing
} @Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
mOutput.setText(charSequence);
mAutofitOutput.setText(charSequence);
} @Override
public void afterTextChanged(Editable editable) {
// do nothing
}
});
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} } MainActivity.java
MianActivity
TextView UI美化-------自适应字体控件的更多相关文章
- iOS开发UI篇—手写控件,frame,center和bounds属性
iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...
- iOS开发UI基础—手写控件,frame,center和bounds属性
iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...
- Kendo UI for Angular 2 控件
Kendo UI for Angular 2 控件 伴随着 Angular 2 的正式 release,Kendo UI for Angular 2 的第一批控件已经发布了,当前是 Beta 版本,免 ...
- Semantic UI中的验证控件的事件的使用
1.Semantic UI中的验证控件,功能挺不错的,中文官网的文档写的都比较详细了,我再这里就不再进行重复了,主要是想说一下它的事件的使用方法,这个可能有部分朋友刚开始接触的时候不太了解 注意看这几 ...
- 使用 Microsoft.UI.Xaml 解决 UWP 控件和对老版本 Windows 10 的兼容性问题
原文 使用 Microsoft.UI.Xaml 解决 UWP 控件和对老版本 Windows 10 的兼容性问题 虽然微软宣称 Windows 10 将是最后一个 Windows 版本,但由于年代跨越 ...
- Android UI组件----ListView列表控件详解
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...
- 界面美化.CStatic控件的美化(好多系列文章)
http://www.cnblogs.com/20090802/archive/2010/09/17/1829283.html 静态控件也是比较常用的控件,在VS开发环境中用的应该挺频繁的吧. 其实m ...
- 【Android Studio】安卓开发初体验3.1——UI设计之常用控件
常用控件 首先对xml文件的编辑有三种模式 Code为纯代码 Split是一边代码,一边预览效果图 Designer就是有UI设计界面 TextView 用于在界面上显示一段文本信息 所有控件都可以在 ...
- 集成 Kendo UI for Angular 2 控件
伴随着 Angular 2 的正式 release,Kendo UI for Angular 2 的第一批控件已经发布了,当前是 Beta 版本,免费使用. 官方站点:Kendo UI for Ang ...
随机推荐
- gearman在虚拟机上运行没有自动开启的处理
几天来被gearman无响应的问题困扰,后来请教了大神解决.原因是gearman在虚拟机上运行不稳定,无法自动开启,需手动开始,输入图片的两行命令即开始.
- MapReduce C++ Library
MapReduce C++ Library for single-machine, multicore applications Distributed and scalable computing ...
- Install hadoop on windows(non-virtual machine, such cygwin)
DownloadBefore starting make sure you have this two softwares Hadoop 2.7.1 Java – Jdk 1.7+ Extract d ...
- Flask 进阶二
flask中的路由系统: endpoint:反向url地址,默认为视图函数名(url_for). from flask import Flask,url_for app = Flask(__name_ ...
- web本质
知识内容: 1.网络协议复习 2.模拟web 3.web本质总结 参考: http://www.cnblogs.com/wupeiqi/articles/5237672.html http://www ...
- python入门-异常
1 报错的例子 print(5/0) 2跳过报错的例子 try: print(5/0) except ZeroDivisionError: print("You can't divide b ...
- js选择器 querySelector
<form method="post" action="" id="myform"> <input type=" ...
- rabbitMQ 的基本知识
参考: https://www.cnblogs.com/dwlsxj/p/RabbitMQ.html
- 自定义BeanUtils
package com.icil.booking.service.util; import java.math.BigDecimal; import java.text.ParseException; ...
- 面向过程中的局部变量(global)
1.school = 'oldboy.edu' def change_name(name): school = " Mage Linux" # 局 ...