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. 第8章 信号(1)_Linux信号处理机制

    1. 信号的基本概念 1.1 基本概念 (1)信号(signal)机制是linux系统中最为古老的进程之间的通信机制,解决进程在正常运行过程中被中断的问题,导致进程的处理流程会发生变化. (2)信号本 ...

  2. spark1.0属性配置以及spark-submit简单使用

    在spark1.0中属性支持三种配置方式: 1.代码 在代码中构造SparkConf时指定master.appname或者key-value等 val conf = new SparkConf(); ...

  3. mysql 不能插入中文和显示中文

    一)不能显示中文解决办法: 参考:http://bbs3.chinaunix.net/thread-880131-1-1.html 1:windows平台,因为windows操作系统默认的是用了gb2 ...

  4. Postman的基础使用

    postman的基础功能,官方文档介绍的是相当啰嗦,所以笔者这里先简单介绍一下主界面,入门功能就都提到了.稍后我们再一一介绍基础功能的使用方法. Collections:在Postman中,Colle ...

  5. jar包双击执行引用外部包问题

    大家都知道一个java应用项目可以打包成一个jar,当然你必须指定一个拥有main函数的main class作为你这个jar包的程序入口. 具体的方法是修改jar包内目录META-INF下的MANIF ...

  6. python学习笔记一和PHP的一些对比

    python和php一样是 解释性语言 php和php一样 定义变量不需要指定类型,C语言中的print函数 在python中也是适用的 python编码 适用缩进  4个空格,通常存储为UTF-8模 ...

  7. python读取excel,数字都是浮点型,日期格式是数字的解决办法

    excel文件内容: 读取excel: # coding=utf-8 import xlrd import sys reload(sys) sys.setdefaultencoding('utf-8' ...

  8. 使用JSP页面生成PDF报表

    转自:http://developer.51cto.com/art/200907/134261.htm 1.iText简介 iText是一个开放源码的Java类库,可以用来方便地生成PDF文件.大家通 ...

  9. java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList

    String[] 转换成 ArrayList 报的错. String[] str = {"A","B"}; ArrayList<String> li ...

  10. JPQL和SQL的比较

    前言 在JAVA EE中,JPQL是专门为Java 应用程序访问和导航实体实例设计的.Java Presistence Query Language(JPQL),java持久性查询语言.它是JPA规范 ...