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美化-------自适应字体控件的更多相关文章

  1. iOS开发UI篇—手写控件,frame,center和bounds属性

    iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...

  2. iOS开发UI基础—手写控件,frame,center和bounds属性

    iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...

  3. Kendo UI for Angular 2 控件

    Kendo UI for Angular 2 控件 伴随着 Angular 2 的正式 release,Kendo UI for Angular 2 的第一批控件已经发布了,当前是 Beta 版本,免 ...

  4. Semantic UI中的验证控件的事件的使用

    1.Semantic UI中的验证控件,功能挺不错的,中文官网的文档写的都比较详细了,我再这里就不再进行重复了,主要是想说一下它的事件的使用方法,这个可能有部分朋友刚开始接触的时候不太了解 注意看这几 ...

  5. 使用 Microsoft.UI.Xaml 解决 UWP 控件和对老版本 Windows 10 的兼容性问题

    原文 使用 Microsoft.UI.Xaml 解决 UWP 控件和对老版本 Windows 10 的兼容性问题 虽然微软宣称 Windows 10 将是最后一个 Windows 版本,但由于年代跨越 ...

  6. Android UI组件----ListView列表控件详解

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...

  7. 界面美化.CStatic控件的美化(好多系列文章)

    http://www.cnblogs.com/20090802/archive/2010/09/17/1829283.html 静态控件也是比较常用的控件,在VS开发环境中用的应该挺频繁的吧. 其实m ...

  8. 【Android Studio】安卓开发初体验3.1——UI设计之常用控件

    常用控件 首先对xml文件的编辑有三种模式 Code为纯代码 Split是一边代码,一边预览效果图 Designer就是有UI设计界面 TextView 用于在界面上显示一段文本信息 所有控件都可以在 ...

  9. 集成 Kendo UI for Angular 2 控件

    伴随着 Angular 2 的正式 release,Kendo UI for Angular 2 的第一批控件已经发布了,当前是 Beta 版本,免费使用. 官方站点:Kendo UI for Ang ...

随机推荐

  1. keras基础-优化策略:mini-batch gradient decent

    参考<Keras中文文档>http://keras-cn.readthedocs.io/en/latest/ 相关概念:神经网络优化器(优化策略).梯度下降.随机梯度下降.小批的梯度下降( ...

  2. Spark分析之TaskScheduler

    TaskScheduler概述: TaskScheduler是一个可插拔任务调度接口,通过不同的SchedulerBackend进行任务的调度.主要功能如下: 1.一个TaskScheduler只为一 ...

  3. PHP mysqli_free_result()与mysqli_fetch_array()函数

    mysql_free_result() 仅需要在考虑到返回很大的结果集时会占用多少内存时调用.在脚本结束后所有关联的内存都会被自动释放. 在我们执行完SELECT语句后,释放游标内存是一个很好的习惯. ...

  4. 尝试了一些时间,最简单的apache上设置用IP访问一个虚拟目录

    就是其实新建一个 多域名访问的设置 <VirtualHost *:80> DocumentRoot /var/www/ ServerName IP</VirtualHost> ...

  5. java的锁机制,synchronize与Lock比较

    参考:https://blog.csdn.net/dahongwudi/article/details/78201082

  6. HTML5 Canvas ( 画一个五角星 ) lineJoin miterLimit

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. Eclipse在线安装STS插件

    转自:https://blog.csdn.net/weixin_41987553/article/details/81091280 spring Boot是由Pivotal团队提供的全新框架,其设计目 ...

  8. Mysql 2条记录 差值计算

    1 表结构 2:  其实 是2个相同的 表根据rownum= rownum-1 来计算,所以先了解单个表的查询 附上SQL: #查询出1天的数据升序 ) as rownum, info.equipme ...

  9. RocketMQ初探(五)之RocketMQ4.2.6集群部署(单Master+双Master+2m+2s+async异步复制)

    以下部署方式结合众多博友的博客,经过自己一步一步实际搭建,如有雷同,侵权行为,请见谅...其中遇到不少的坑,希望能帮到更多的人,现在很少能找到一份完整版4.2.6版本的搭建教程了,如果你有幸遇见,那么 ...

  10. UI5-文档-4.28-Unit Test with QUnit

    现在我们在应用程序中有了一个测试文件夹,我们可以开始增加我们的测试覆盖率. 实际上,到目前为止我们添加到应用程序中的每个特性都需要单独的测试用例.到目前为止,我们完全忽略了这一点,所以让我们为步骤23 ...