android入门(一)---UI组件之文本框(TextView)

女爷i 2022-08-09 11:59 324阅读 0赞

#

  1. 以前学习Android不做笔记,有的甚至只是看看就过去了,都不实际操作一遍。一段时间以后已经遗忘了,尤其是学到后面需要综合运用的时候,就感觉到什么都不会了。这或许就是欲速则不达,所以从今天开始,学会一点就做一点笔记,一方面是增加理解,另一方面也为了以后查找方便。

一、文本增加连接

  1. 对普通文本中的电话号、邮箱、网址等增加链接,代码如下:
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:paddingBottom="@dimen/activity_vertical_margin"
  7. android:paddingLeft="@dimen/activity_horizontal_margin"
  8. android:paddingRight="@dimen/activity_horizontal_margin"
  9. android:paddingTop="@dimen/activity_vertical_margin"
  10. tools:context=".MainActivity" >
  11. <TextView
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:autoLink="phone|email"
  15. android:singleLine="true"
  16. android:text="手机号码:15598367088,邮箱地址:123456789@qq.com" />
  17. </RelativeLayout>
  18. 运行结果如下:
  19. TextView组件属性解释:
  20. singleLine:设置单行显示,如果一行显示不完的话,就用...表示后面的文本;
  21. autoLink:将指定文本转换为可单击的超链接形式,属性值有:none,map,phone,email.all,web;当有两种以上要同时显示时,使用“|”。

二、带图片的TextView组件

  1. 代码:
  2. <TextView
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:drawableTop="@drawable/ic_launcher"
  6. android:text="我是TextView组件,带有图片"
  7. android:textSize="20pt"
  8. android:gravity="center"
  9. />运行结果截图:
  10. TextView组件属性解释:
  11. textSize:文本大小;
  12. drawableTop:设置图片在文字的上面;
  13. gravityTextView组件位置居中。
  14. 说明:pt: point,是一个标准的长度单位,1pt1/72英寸,用于印刷业。

三、文本阴影效果

  1. 代码如下:
  2. <TextView
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:textSize="20pt"
  6. android:text="TextView阴影..."
  7. android:shadowColor="#FF7800"
  8. android:shadowRadius="3.0"
  9. android:shadowDx="10.0"
  10. android:shadowDy="10.0"
  11. />运行结果截图:
  12. TextView 组件属性解释:
  13. shadowColor:指定文本的阴影颜色,需要与shodowRadius一起使用;
  14. shadowRadius:阴影的模糊程度,设为0.1就本城字体颜色了,建议设为3.0
  15. shadowDx:设置阴影在水平方向的偏移,即水平阴影开始的横坐标位置;
  16. shadowDy:设置阴影在竖直方向的偏移,即竖直方向阴影开始的纵坐标位置。

四、带边框的TextView

  1. 代码如下:
  2. <TextView
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:textSize="20pt"
  6. android:text="带边框的TextView(文本)"
  7. android:background="@drawable/border"
  8. />TextView组件属性解释:
  9. background:加载背景颜色,北京图片的属性;
  10. border:是加载drawable文件夹下面的border.xml文件
  11. border.xml文件是drawable文件夹下的xml文件,用于绘制边框,添加TextView组件的背景颜色,代码如下:
  12. <?xml version="1.0" encoding="utf-8"?>
  13. <shape xmlns:android="http://schemas.android.com/apk/res/android" >
  14. <!-- 设置一个蓝色边框 -->
  15. <stroke
  16. android:width="15px"
  17. android:color="#073878" />
  18. <!-- 指定渐变背景色,使用sweep类型的渐变 -->
  19. <gradient
  20. android:centerColor="#FCA974"
  21. android:endColor="#F80000"
  22. android:startColor="#81D33F"
  23. android:type="sweep" />
  24. </shape> border.xml中代码解释: pxpixels(像素),不同设备显示效果相同,一般我们HVGA代表320*480,这个用的比较多。 shape:用于设定形状; stroke:描边,边框; gradient:渐变 sweep:扫描线式的渐变 结果截图: 五、圆角边框
  25. 代码如下:
  26. <TextView
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content"
  29. android:textSize="20pt"
  30. android:textColor="#FFAAFF"
  31. android:text="圆角边框的TextView"
  32. android:background="@drawable/border"
  33. />
  34. border.xml文件:背景颜色的代码:
  35. <?xml version="1.0" encoding="utf-8"?></span>
  36. <shape xmlns:android="http://schemas.android.com/apk/res/android" >
  37. <!-- 设置一个蓝色边框 -->
  38. <stroke
  39. android:width="5px"
  40. android:color="#073878" />
  41. <!-- 设置四个圆角的半径 -->
  42. <corners
  43. android:bottomLeftRadius="20px"
  44. android:bottomRightRadius="20px"
  45. android:topLeftRadius="20px"
  46. android:topRightRadius="10px" />
  47. </shape>
  48. TextView 组件属性解释:
  49. corner:圆角
  50. </pre>

发表评论

表情:
评论列表 (有 0 条评论,324人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Android UI

    基本组件: 1. 文本类组件 2. 按钮类组件 3. 日期时间类组件 一、文本框组件 文本框文字默认自动换行显示,若不想让其换行,可使用android:sing

    相关 Android详解—TextView

    这篇博文献给正在android学习路上的弟弟,希望有一天以下内容对你有所帮助。 了解一个类,首先要了解他的结构,尤其是API中的这种类。 先了解下`TextView`的结构