android入门(一)---UI组件之文本框(TextView)
#
以前学习Android不做笔记,有的甚至只是看看就过去了,都不实际操作一遍。一段时间以后已经遗忘了,尤其是学到后面需要综合运用的时候,就感觉到什么都不会了。这或许就是欲速则不达,所以从今天开始,学会一点就做一点笔记,一方面是增加理解,另一方面也为了以后查找方便。
一、文本增加连接
对普通文本中的电话号、邮箱、网址等增加链接,代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone|email"
android:singleLine="true"
android:text="手机号码:15598367088,邮箱地址:123456789@qq.com" />
</RelativeLayout>
运行结果如下:
TextView组件属性解释:
singleLine:设置单行显示,如果一行显示不完的话,就用...表示后面的文本;
autoLink:将指定文本转换为可单击的超链接形式,属性值有:none,map,phone,email.all,web;当有两种以上要同时显示时,使用“|”。
二、带图片的TextView组件
代码:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_launcher"
android:text="我是TextView组件,带有图片"
android:textSize="20pt"
android:gravity="center"
/>运行结果截图:
TextView组件属性解释:
textSize:文本大小;
drawableTop:设置图片在文字的上面;
gravity:TextView组件位置居中。
说明:pt: point,是一个标准的长度单位,1pt=1/72英寸,用于印刷业。
三、文本阴影效果
代码如下:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20pt"
android:text="TextView阴影..."
android:shadowColor="#FF7800"
android:shadowRadius="3.0"
android:shadowDx="10.0"
android:shadowDy="10.0"
/>运行结果截图:
TextView 组件属性解释:
shadowColor:指定文本的阴影颜色,需要与shodowRadius一起使用;
shadowRadius:阴影的模糊程度,设为0.1就本城字体颜色了,建议设为3.0;
shadowDx:设置阴影在水平方向的偏移,即水平阴影开始的横坐标位置;
shadowDy:设置阴影在竖直方向的偏移,即竖直方向阴影开始的纵坐标位置。
四、带边框的TextView
代码如下:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20pt"
android:text="带边框的TextView(文本)"
android:background="@drawable/border"
/>TextView组件属性解释:
background:加载背景颜色,北京图片的属性;
border:是加载drawable文件夹下面的border.xml文件
border.xml文件是drawable文件夹下的xml文件,用于绘制边框,添加TextView组件的背景颜色,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 设置一个蓝色边框 -->
<stroke
android:width="15px"
android:color="#073878" />
<!-- 指定渐变背景色,使用sweep类型的渐变 -->
<gradient
android:centerColor="#FCA974"
android:endColor="#F80000"
android:startColor="#81D33F"
android:type="sweep" />
</shape> border.xml中代码解释: px:pixels(像素),不同设备显示效果相同,一般我们HVGA代表320*480,这个用的比较多。 shape:用于设定形状; stroke:描边,边框; gradient:渐变 sweep:扫描线式的渐变 结果截图: 五、圆角边框
代码如下:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20pt"
android:textColor="#FFAAFF"
android:text="圆角边框的TextView"
android:background="@drawable/border"
/>
border.xml文件:背景颜色的代码:
<?xml version="1.0" encoding="utf-8"?></span>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 设置一个蓝色边框 -->
<stroke
android:width="5px"
android:color="#073878" />
<!-- 设置四个圆角的半径 -->
<corners
android:bottomLeftRadius="20px"
android:bottomRightRadius="20px"
android:topLeftRadius="20px"
android:topRightRadius="10px" />
</shape>
TextView 组件属性解释:
corner:圆角
</pre>
还没有评论,来说两句吧...