博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TextView UI美化-------自适应字体控件
阅读量:4569 次
发布时间:2019-06-08

本文共 2671 字,大约阅读时间需要 8 分钟。

http://www.cnblogs.com/psuwgipgf/p/4874158.html

 

一、 TextView字体随大小变化自适应TextView

 

实现依靠于第三方类库

第三方类来源:

下载地址:

使用时先导入类库

以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 
2
6
11
18
23
31
36
46
47
48 49 activity_main.xml
activity_main

 

String.xml

1 
2
3 4
Texttest
5
Settings
6
Hello world!
7 8
text
9
Normal:
10
Autofit:
11 12
This is an example
13 14
String.xml

activity

1 package com.example.texttest; 2  3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.text.Editable; 6 import android.text.TextWatcher; 7 import android.view.Menu; 8 import android.widget.EditText; 9 import android.widget.TextView;10 11 public class MainActivity extends Activity {12 13     private TextView mOutput;14     private TextView mAutofitOutput;15     @Override16     protected void onCreate(Bundle savedInstanceState) {17         super.onCreate(savedInstanceState);18         setContentView(R.layout.activity_main);19         mOutput = (TextView)findViewById(R.id.output);20         mAutofitOutput = (TextView)findViewById(R.id.output_autofit);21 22         ((EditText)findViewById(R.id.input)).addTextChangedListener(new TextWatcher() {23             @Override24             public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {25                 // do nothing26             }27 28             @Override29             public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {30                 mOutput.setText(charSequence);31                 mAutofitOutput.setText(charSequence);32             }33 34             @Override35             public void afterTextChanged(Editable editable) {36                 // do nothing37             }38         });39     }40     41 42 43     @Override44     public boolean onCreateOptionsMenu(Menu menu) {45         // Inflate the menu; this adds items to the action bar if it is present.46         getMenuInflater().inflate(R.menu.main, menu);47         return true;48     }49     50 }51 52 MainActivity.java
MianActivity

 

转载于:https://www.cnblogs.com/bimingcong/p/4874936.html

你可能感兴趣的文章
C# 中的特性 Attribute
查看>>
Microsoft SQL Server, Error: 15128 ()
查看>>
§ 理论基础
查看>>
Atitit. . 软件命名空间与类名命名单词的统计程序设计v2
查看>>
Atitit.如何建立研发体系
查看>>
HttpHandler给本站加图片水印
查看>>
HTML Music Entities/音乐符号
查看>>
Linux signal 处理
查看>>
Oracle中merge into语法
查看>>
Vue2.x + vux2.x + vux-loader + typescript 搭建第一个环境
查看>>
MySQL的binlog日志
查看>>
vagrant The specified host network collides with a non-hostonly network!
查看>>
0x59 单调队列优化DP
查看>>
mysql中的union用法
查看>>
利用python爬取龙虎榜数据及后续分析
查看>>
Git和GitHub使用总结
查看>>
php array_multisort对数据库结果多个字段进行排序
查看>>
关于大型网站技术演进的思考(十六)--网站静态化处理—前后端分离—下(8)...
查看>>
Python中dict详解
查看>>
[LeetCode][JavaScript]House Robber
查看>>