TextView 使用详解

极力推荐文章:欢迎收藏
Android 干货分享

阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android
本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:
一、TextView 继承关系
二、TextView 简单使用举例
三、TextView 跑马灯效果
四、TextView末尾省略号属性
五、TextView 颜色、字体大小属性
六、TextView位置属性
七、TextView 包含图片超链 背景 垂直居中等属性
一、TextView 继承关系
TextView 继承关系如下:
java.lang.Object
↳ android.view.View
↳ android.widget.TextView
TextView 官网api 文档如下:
二、TextView 简单使用举例
使用 xml 布局跟java代码动态设置TextView。
xml布局如下
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_view_id"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/hello" />
</LinearLayout>
java代码中使用方法如下:
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView helloTextView = (TextView) findViewById(R.id.text_view_id);
helloTextView.setText(R.string.user_greeting);
}
}
三、TextView 跑马灯效果
TextView 跑马灯 效果使用方法如下:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="一、跑马灯 效果 eg:ellipsize 欢迎关注 程序员Android 获取更多Android 开发资料、干货、学习视频!"
android:textSize="16sp" />
实现效果如下:

四、TextView末尾省略号属性
TextView末尾省略号属性实现如下:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:singleLine="true"
android:text="二、末尾省略号效果 eg: ellipsize 属性 控制 省略号的位置 (开始 中间 结尾 跑马灯) "
android:textSize="16sp" />
实现效果如下:

五、TextView 颜色、字体大小属性
TextView 字体颜色、大小设置如下:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="三、字体颜色、字体大小 eg:textColor 红色 textSize 16sp"
android:textColor="#F00"
android:textSize="16sp" />
实现效果如下:

六、TextView位置属性
TextView 位置居中属性设置如下:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="四、字体位置属性 eg:居中 "
android:textColor="#FF6100"
android:textSize="16sp" />
实现效果如下:

七、TextView 包含图片超链 背景 垂直居中等属性
TextView 设置超链点击,左侧图片、垂直居中等属性如下:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="email"
android:background="@android:color/white"
android:drawableLeft="@drawable/ic_launcher"
android:gravity="center_vertical"
android:linksClickable="true"
android:text="五、\n1.左侧包含图片 drawableLeft \n2.背景 颜色 白色 background \n3. 邮箱超链: autoLink eg :1150580768@qq.com"
android:textColor="@android:color/black"
android:textSize="16sp" />
实现效果如下:

至此,本篇已结束,如有不对的地方,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!

TextView 使用详解的更多相关文章
- Android textAppearance的属性设置及TextView属性详解
textAppearance的属性设置 android:textAppearance="?android:attr/textAppearanceSmall" android:tex ...
- Android控件Editext、TextView属性详解
EditText属性描述 android:layout_gravity="center_vertical"//设置控件显示的位置:默认top,这里居中显示,还有bottom and ...
- TextView属性详解
android:autoLink设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web/email/phone/map/all)android:a ...
- android TextView属性详解
RelativeLayout用到的一些重要的属性: 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 android:l ...
- Android TextView和EditText属性详解
TextView属性详解: autoLink设置 是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web /email/phone/map/all) ...
- Android之TextView的样式类Span的使用详解
Android中的TextView是个显示文字的的UI类,在现实中的需求中,文字有各式各样的样式,TextView本身没有属性去设置实现,我们可以通过Android提供的 Spannab ...
- Android:TextView跑马灯-详解
Android:TextView跑马灯_详解 引言: TextView之所以需要跑马灯,是由于文字太长,或者是吸引眼球. 关键代码如下: android:singleLine="true&q ...
- Android开发:文本控件详解——TextView(一)基本属性
一.简单实例: 新建的Android项目初始自带的Hello World!其实就是一个TextView. 在activity_main.xml中可以新建TextView,从左侧组件里拖拽到右侧预览界面 ...
- 2.3.1 TextView(文本框)详解
http://www.runoob.com/w3cnote/android-tutorial-textview.html 1.基础属性详解: 通过下面这个简单的界面,我们来了解几个最基本的属性: 布局 ...
随机推荐
- SQL Server温故系列(1):SQL 数据操作 CRUD 之增删改合
1.插入语句 INSERT INTO 1.1.用 INSERT 插入单行数据 1.2.用 INSERT 插入多行数据 1.3.用 INSERT 插入子查询结果行 1.4.INSERT 小结及特殊字段插 ...
- mysql报错(Not unique table/alias)
Not unique table/alias 错误编号:1066 问题分析: SQL 语句中出现了非唯一的表或别名. 解决方法: 1.请检查出现问题位置的 SQL 语句中是否使用了相同的表名,或是定义 ...
- CentOS 6.x 安装 JDK1.8
安装方式:rpm(此方式不需要手动配置环境变量) 1. 查看系统是否自带了jdk 查看centos是否自带了openjdk,如果有则卸载掉(当然也可以不卸载,但要注意冲突及版本的使用) # 查看 rp ...
- springboot使用RabbitMQ实现延时任务
延时队列顾名思义,即放置在该队列里面的消息是不需要立即消费的,而是等待一段时间之后取出消费.那么,为什么需要延迟消费呢?我们来看以下的场景 订单业务: 在电商/点餐中,都有下单后 30 分钟内没有付款 ...
- CPU缓存和内存屏障
CPU性能优化手段 - 缓存 为了提高程序的运行性能, 现代CPU在很多方面对程序进行了优化例如: CPU高速缓存, 尽可能的避免处理器访问主内存的时间开销, 处理器大多会利用缓存以提高性能 多级缓存 ...
- 一个简单的EJB例子
转载自 http://blog.sina.com.cn/s/blog_678530f60100hvwy.html 声明:这个Converter的例子应该是J2EE 1.4 Tutorial上面的.不过 ...
- android_SurfaceView 画图
有这样一种view类,可以让人在其上面画动画,画图片,它的全名叫做surfaceview.名称就包含两层意思,一层是surface,一层是view.前一层提供一个面可以让人画画,后一层是个view,可 ...
- 20131227-backgroundPosition
background-position 用法详细介绍 语法: background-position : length || length background-position : position ...
- opatch卸载weblogic12.1.3.0补丁
1.首先进入opatch目录 2.查看opatch命令(心急于卸载的朋友直接跳过这步) [weblogic@localhost OPatch]$ ./opatch -help Oracle 中间补丁程 ...
- python的ORM技巧记录
# -*- coding:utf-8 -*- from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, In ...