TextView的使用

一、TextView常用属性:

//设置id
android:id

//设置控件高度
android: layout_height

//设置控件高度
android:layout_width

//设置文本
android:Text

//设置文本颜色
android:TextColor

//设置文本大小
android:TextSize

//设置文本行数--替换了android:maxLines和android:minLines
android:lines

//设置文本每行最大字节数(后面数字的单位为字节!)
android:maxEms

/**
* 匹配文本模式--取值:none/web/email/phone/map/all
* 
*  @param none    不自动匹配
*  @param web     匹配网站
*  @param email   匹配邮箱
*  @param phone   匹配电话
*  @param map     匹配地址--点击打开google地图,需要输入英文地址--不建议使用
*  @param all     匹配所有
*/
android:autoLink

/**
* 设置文字过长时,文本如何显示--取值:start/end/middle/marquee
* 
* @param start   省略号显示在开头
* @param end     省略号显示在结尾
* @param middle  省略号显示在中间
* @param marquee 跑马灯效果(横向动画)     
* 
* 注意:
*     1.该方法建议设置: android:lines="1";
*     2.使用该方法时,设置android:inputType会导致冲突,使得"..."显示不出来
*     3.设置跑马灯效果,需要设置
*     android:focuseable=true;
*     android:focusableInTouchMode="true"
*     注意:
*         只能设置android:singleLine="true"
*         不能使用android:lines="1"
*         同时与android:typeface冲突
*/
android:ellipsize

/**
*  设置文本样式--取值:serif/sans/normal/monospace
*   
*  @param serif      serif字体
*  @param sans       sans字体 
*  @param normal     默认字体
*  @param monospace  等宽字体
*/
android:typeface

二、TextView布局属性

//设置TextView在父容器中的位置
android:layout_gravity

//设置文本在TextView中的位置
android:gravity

//设置外间距--即上下左右均有外间距
android:layout_margin

//设置控件左外间距
android:layout_marginLeft

//设置控件右外间距
android:layout_marginRight

//设置控件上外间距
android:layout_marginTop

//设置控件下外间距
android:layout_marginBottom

//设置控件内间距--即上下左右均有内间距
android:layout_padding

//设置控件左内间距
android:layout_paddingLeft

//设置控件右内间距
android:layout_paddingRight

//设置控件下间距
android:layout_paddingBottom

//设置控件上间距
android:layout_paddingTop

三、TextView特殊布局属性

从Android4.2开始使用,Android开始支持一种RTL(Right to Left)布局.

该布局经常被使用在阿拉伯语、希腊语等环境中。

Android默认UI布局为LTR(Left to Right)

RTL布局是默认关闭的,如果需要开启:

1.AndroidMainifest.xml文件中将applicaiton标签的android:supportsRtl设置为true

//设置支持RTL模式
android:supportRtl="true";

2.在相对应的布局中设置android:layoutDirection属性为TRL

//设置阅读模式为RTL
android:layoutDirection="rtl"

3.RTL对应的属性

//RTL相当于marginRight,LTR相当于marginLeft
android:layout_marginStart

//RTL相当于marginLeft,LTR相当于marginRight
android:layout_marginEnd

//RTL相当于paddingRight,LTR相当于paddingLeft
android:layout_paddingStart

//RTL相当于paddingLeft,LTR相当于paddingRight
android:layout_paddingEnd

四、TextView图片设置

//在文本左侧显示图片
android:drawableLeft

//在文本右侧显示图片
android:drawableRight

//在文本上方显示图片
android:drawableTop

//在文本下方显示图片
android:drawableBottom

五、 TextView 阴影属性

//设置文本阴影颜色
android:shadowColor

//设置文本阴影半径--输入的值为数字,不带单位  eg:5
android:shadowRadius

//设置X轴阴影偏移值--输入的值为数字,不带单位 eg:5
android:shadowDx

//设置Y轴阴影偏移值--输入的值为数字,不带单位 eg:5
android:shadowDy

备注:该博客内容尚未完成,正在更新中

最新更新时间—-2017/10/17

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值