android-UI组件实例大全(一)------TextView文本框
来源:互联网 发布:淘宝投诉怎么撤销 编辑:程序博客网 时间:2024/06/05 06:57
小知识点:
dp(dip): device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA、HVGA和QVGA 推荐使用这个,不依赖像素。
px: pixels(像素). 不同设备显示效果相同,一般我们HVGA代表320x480像素,这个用的比较多。
pt: point,是一个标准的长度单位,1pt=1/72英寸,用于印刷业,非常简单易用;
sp: scaled pixels(放大像素). 主要用于字体显示best for textsize。
文本框(TextView)
TestView代码实例:
1.对电话与邮件增加链接:
代码:
- <span style="font-family:Comic Sans MS"> <!-- 对电话与邮件增加链接 -->
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:text="手机号码12345678821,邮箱地址779878443@qq.com"
- android:autoLink="phone|email"
- /></span>
运行截图:
代码解释:
singleLine:设置单行显示,如果一行显示不完的话,就用...表示后面的文本
autoLink:将指定文本转换为可单击的超链接形式,属性值有:none,map,phone,email.all,web;可写成上面那种形式,两种超链接类型
2.定义一个带图片的TextView,字体大小为20pt,且图片在文本上方
代码:
- <span style="font-family:Comic Sans MS"><!-- 定义一个带图片的TextView,且图片在文本上方 -->
- <TextView
- android:textSize="20pt"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="我是一个带图片的TextView"
- android:drawableTop="@drawable/ic_launcher"
- /></span>
运行截图:
代码解释:
textSize:设置TextView显示文本的大小
drawableTop:设置图片的位置,这里的话我们设置为文字上面,当然你也可以设置他在左右或者底部改下drawableLeft这样就可以了
3.设置文本的颜色,并使用阴影效果:
这里要注意一点:阴影效果在adt上是不显示的,需要运行在avd上才能看到效果哦!
代码:
- <!-- 设置文字颜色,使用阴影效果 -->
- <TextView
- android:textSize="20pt"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="#841271"
- android:text="我有阴影....."
- android:shadowColor="#567841"
- android:shadowRadius="3.0"
- android:shadowDx="10.0"
- android:shadowDy="10.0"
- />
运行截图:
代码解释:
textColor:设置文本的颜色
shadowColor:指定文本的阴影颜色,需要与shadowRadius一起使用
shadowRadius:设置阴影的模糊程度,设为0.1就变成字体颜色了,建议使用3.0
shadowDx:设置阴影在水平方向的偏移,就是水平方向阴影开始的横坐标位置
shadowDy:设置阴影在竖直方向的偏移,就是竖直方向阴影开始的纵坐标位置
4.定义一个边框的TextView
我们都知道textview并没有边框,如果要实现有边框的textview只能用背景了
代码:
- <!-- 带边框的TextView -->
- <TextView
- android:textSize="20pt"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="带边框的文本..."
- android:background="@drawable/border"
- />
border.xml是建立在drawable的一个xml文件,用于绘制边框
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android" >
- <!-- 设置一个蓝色边框 -->
- <stroke android:width="4px" android:color="#07387B"/>
- <!-- 制定渐变背景色,使用sweep类型的渐变 -->
- <gradient
- android:startColor="#81D33F"
- android:centerColor="#FCA974"
- android:endColor="#F80000"
- android:type="sweep"
- />
- </shape>
运行截图:
代码分析:
background:设置textview的背景
- android:width:设置边框的粗细,这里设为4px,四个像素点
shape优化界面详解见:
http://tech.ddvip.com/2012-10/1351226528184208.html
5.定义圆角边框的TextView
代码:
- <!-- 带圆角边框的TextView -->
- <TextView
- android:textSize="20pt"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="圆角边框"
- android:background="@drawable/border"
- />
border.xml文件:背景图片
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android" >
- <!-- 设置透明背景色 -->
- <solid android:color="#000"/>
- <!-- 设置一个绿色边框 -->
- <stroke android:width="4px" android:color="#00FF00"/>
- <!-- 设置四个圆角的半径 -->
- <corners
- android:topLeftRadius="20px"
- android:topRightRadius="10px"
- android:bottomRightRadius="20px"
- android:bottomLeftRadius="10px"
- />
- </shape>
运行截图:
这个很简单,注释很详细地介绍了这里就略过了
- android-UI组件实例大全(一)------TextView文本框
- android-UI组件实例大全(一)------TextView文本框
- android-UI组件实例大全(一)------TextView文本框
- android-UI组件实例大全(一)------TextView文本框
- android入门(一)---UI组件之文本框(TextView)
- 常用UI组件(widgets)之文本框(TextView)(一)
- android-UI组件实例大全(八)------Adapter类Two之Autocompletion自动完成文本框
- Android用户界面 UI组件--TextView及其子类(一) TextView
- android基础之UI设计与开发一textView大全
- Android UI之TextView组件
- Android常用UI组件 - TextView
- android UI组件大全
- android-UI组件实例大全(二)------EditText编辑框
- android-UI组件实例大全(六)------ImageView图像视图
- android-UI组件实例大全(十二)------ScrollView滚动视图
- android-UI组件实例大全(十六)---菜单Menu
- UI组件之TextView及其子类(一)TextView和EditText
- Android开发之UI组件TextView
- Swift学习,常量与变量(二)
- 仿ios日期选择控件
- Android Studio导入第三方库报错处理
- uboot命令的实现
- 轻松把玩HttpClient之配置ssl,采用设置信任自签名证书实现https
- android-UI组件实例大全(一)------TextView文本框
- Android不规则点击区域详解
- SQL 语句
- 多线程学习--案例-子线程循环10次,接着主线程循环100,接着又回到子线程循环10次,接着再回到主线程又循环100,如此循环50次
- hibernate中hbm的级联操作(多对多)
- failed to create java virtual machine的解决方法
- 快速排序1.0
- Android Fragment 间通信
- BAT解密:互联网技术发展之路(2)- 业务如何驱动技术发展