Android软件开发之TextView详解(六)

来源:互联网 发布:通达信金融炒股软件 编辑:程序博客网 时间:2024/05/29 14:27
Android软件开发之TextView详解

TextView的API 中文文档中 说明它的结构

结构
java.lang.Object
   android.view.View
        android.widget.TextView
直接子类:
    Button, CheckedTextView, Chronometer, DigitalClock, EditText
间接子类:
     AutoCompleteTextView, CheckBox, CompoundButton, ExtractEditText,MultiAutoCompleteTextView, RadioButton, ToggleButton
1.TextView中链接手机号码/网页/邮件/地图

android:autoLink的可选值为(none/web/email/phone/map/all) 设置一个URL链接 ,可以点击访问。

例如:android:text="拨打手机:13888888888"
            android:autoLink="phone"

         这里设置了一个链接为手机的autoLink  它会自动设别数字 过滤掉字符串"拨打手机:" 从而点击号码后会转跳到系统拨号码的界面可以拨打电话。

拨打手机号码:
  1.         <TextView android:id="@+id/textView0"
  2.                   android:layout_width="fill_parent"
  3.                           android:layout_height="wrap_content" 
  4.                           android:textColor="#FF0000"
  5.                           android:textSize="18dip"
  6.                           android:background="#FFFFFF"
  7.                       android:text="拨打手机:13888888888" 
  8.                       android:gravity="center_vertical|center_horizontal"
  9.                       android:autoLink="phone"
  10.                       />
复制代码
访问web网页:
  1.         <TextView android:id="@+id/textView1"
  2.                   android:layout_width="fill_parent"
  3.                           android:layout_height="wrap_content" 
  4.                           android:textColor="#FF0000"
  5.                           android:textSize="18dip"
  6.                           android:background="#00FF00"
  7.                       android:text="雨松MOMO的博客:http://blog.csdn.net/xys289187120" 
  8.                       android:gravity="center_vertical|center_horizontal"
  9.                       android:autoLink="web"
  10.                       />
复制代码
发送邮件:


首选须要设置自己的电子邮件 否则Android是不知道你从那里发的邮件
  1.         <TextView android:id="@+id/textView2"
  2.                   android:layout_width="fill_parent"
  3.                           android:layout_height="wrap_content" 
  4.                           android:textColor="#FF0000"
  5.                           android:textSize="18dip"
  6.                           android:background="#FFFF00"
  7.                       android:text="发送邮件:xuanyusong@gmail.com" 
  8.                       android:gravity="center_vertical|center_horizontal"
  9.                       android:autoLink="email"
  10.                       />
复制代码
谷歌地图:

设置 android:autoLink="map"后需要有google地图才可以 否则会报错



2.在TextView中显示图片

通过设置背景的方式显示
android:background="@drawable/icon" 

设置图片在textView的锚点位置
android:drawableBottom="@drawable/icon"
android:drawableTop="@drawable/icon"
android:drawableLeft="@drawable/icon"
android:drawableRight="@drawable/icon"
  1.         <TextView android:id="@+id/TextView01" 
  2.                   android:layout_width="wrap_content" 
  3.                   android:layout_height="wrap_content"
  4.                   android:text="在图片下方"
  5.                   android:textColor="#FF0000"
  6.                   android:drawableBottom="@drawable/jay"
  7.                   android:layout_alignParentTop="true"
  8.                   android:layout_centerHorizontal="true"
  9.                   >
  10.          </TextView>
  11.   
  12.          <TextView android:id="@+id/TextView01" 
  13.                   android:layout_width="wrap_content" 
  14.                   android:layout_height="wrap_content"
  15.                   android:text="在图片上方"
  16.                   android:textColor="#FF0000"
  17.                   android:drawableTop="@drawable/jay"
  18.                   android:layout_alignParentBottom="true"
  19.                   android:layout_centerHorizontal="true"
  20.                   >
  21.          </TextView> 
  22.          <TextView android:id="@+id/TextView01"  
  23.                   android:layout_width="wrap_content" 
  24.                   android:layout_height="wrap_content"
  25.                   android:text="在图片左边"
  26.                   android:textColor="#FF0000"
  27.                   android:drawableLeft="@drawable/jay"
  28.                  android:layout_alignParentLeft="true"
  29.                   android:layout_centerVertical="true"
  30.                   >
  31.          </TextView>    
  32.          <TextView android:id="@+id/TextView01" 
  33.                   android:layout_width="wrap_content" 
  34.                   android:layout_height="wrap_content"
  35.                   android:text="在图片右边"
  36.                   android:textColor="#FF0000"
  37.                   android:drawableRight="@drawable/jay"
  38.                   android:layout_alignParentRight="true"
  39.                   android:layout_centerVertical="true"
  40.                   >
  41.          </TextView>
复制代码
3.文本显示内容的处理

  可以在textView中设置我们想要的任何效果

  1.         <TextView android:layout_width="fill_parent"
  2.                           android:layout_height="wrap_content" 
  3.                           android:textColor="#000000"
  4.                           android:textSize="18dip"
  5.                           android:background="#00FF00"
  6.                       android:text="文本内容" 
  7.                       android:gravity="center_vertical|center_horizontal"
  8.         />
  9.         
  10.         <TextView android:layout_width="fill_parent"
  11.                           android:layout_height="wrap_content" 
  12.                       android:textSize="18dip"
  13.                       android:background="#FFFFFF"
  14.                       android:textColor="#FF0000"
  15.                       android:text="设置字符串显示为*" 
  16.                       android:gravity="center_vertical|center_horizontal"
  17.                       />
  18.         <TextView android:layout_width="fill_parent"
  19.                           android:layout_height="wrap_content" 
  20.                       android:textSize="18dip"
  21.                       android:background="#FFFFFF"
  22.                       android:textColor="#FF0000"
  23.                       android:text="设置字符串显示为*"
  24.                       android:password="true" 
  25.                       android:gravity="center_vertical|center_horizontal"
  26.                       />
  27.         <TextView android:layout_width="fill_parent"
  28.                           android:layout_height="wrap_content" 
  29.                       android:textSize="18dip"
  30.                       android:background="#FF0000"
  31.                       android:textColor="#FFFFFF"
  32.                       android:text="设置字符串阴影颜色"
  33.                       android:shadowColor="#000000"
  34.                       android:shadowRadius="3.0"
  35.                       android:gravity="center_vertical|center_horizontal"
  36.                       />
  37.         <TextView android:layout_width="fill_parent"
  38.                           android:layout_height="wrap_content" 
  39.                       android:textSize="18dip"
  40.                       android:background="#FFFFFF"
  41.                       android:textColor="#FF0000"
  42.                       android:singleLine="true"
  43.                       android:text="只显示一行字符串超出屏幕为'...'dsfusdiofjdsiofjsdiofjoisdjfiosdjfoisdjfoisdf"
  44.                       android:gravity="center_vertical|center_horizontal"
  45.                       />
  46.         <TextView android:layout_width="fill_parent"
  47.                           android:layout_height="wrap_content" 
  48.                       android:textSize="18dip"
  49.                       android:background="#FF0000"
  50.                       android:textColor="#FFFFFF"
  51.                       android:text="设置显示文字的间隔为0.5"
  52.                       android:textScaleX="0.5"
  53.                       android:gravity="center_vertical|center_horizontal"
  54.                       />
  55.         <TextView android:layout_width="fill_parent"
  56.                           android:layout_height="wrap_content" 
  57.                       android:textSize="18dip"
  58.                       android:background="#FF0000"
  59.                       android:textColor="#FFFFFF"
  60.                       android:text="设置显示文字的间隔为2.0"
  61.                       android:textScaleX="2.0"
  62.                       android:gravity="center_vertical|center_horizontal"
  63.                       />
  64.         <TextView android:layout_width="fill_parent"
  65.                           android:layout_height="wrap_content" 
  66.                       android:textSize="18dip"
  67.                       android:background="#FFFFFF"
  68.                       android:textColor="#FF0000"
  69.                       android:text="设置文字外形为 bold"
  70.                       android:textStyle="bold"
  71.                       android:gravity="center_vertical|center_horizontal"
  72.                       />
  73.         <TextView android:layout_width="fill_parent"
  74.                           android:layout_height="wrap_content" 
  75.                       android:textSize="18dip"
  76.                       android:background="#FFFFFF"
  77.                       android:textColor="#FF0000"
  78.                       android:text="设置文字外形为 normal"
  79.                       android:textStyle="normal"
  80.                       android:gravity="center_vertical|center_horizontal"
  81.                       />
  82.         <TextView android:layout_width="fill_parent"
  83.                           android:layout_height="wrap_content" 
  84.                       android:textSize="18dip"
  85.                       android:background="#FFFFFF"
  86.                       android:textColor="#FF0000"
  87.                       android:text="设置文字外形为 italic"
  88.                       android:textStyle="italic"
  89.                       android:gravity="center_vertical|center_horizontal"
  90.                       />
  91.                         <TextView android:layout_width="fill_parent"
  92.                           android:layout_height="wrap_content" 
  93.                       android:background="#FFFFFF"
  94.                       android:textColor="#FF0000"
  95.                       android:text="设置文字大小   为10"
  96.                       android:textSize="10dip"
  97.                       android:gravity="center_vertical|center_horizontal"
  98.                       />
  99.                     <TextView android:layout_width="fill_parent"
  100.                           android:layout_height="wrap_content" 
  101.                       android:background="#FFFFFF"
  102.                       android:textColor="#FF0000"
  103.                       android:text="设置文字大小   为15"
  104.                       android:textSize="15dip"
  105.                       android:gravity="center_vertical|center_horizontal"
  106.                       />
  107.                     <TextView android:layout_width="fill_parent"
  108.                           android:layout_height="wrap_content" 
  109.                       android:background="#FFFFFF"
  110.                       android:textColor="#FF0000"
  111.                       android:text="设置文字大小   为20"
  112.                       android:textSize="20dip"
  113.                       android:gravity="center_vertical|center_horizontal"
  114.                       />
  115.             <TextView 
  116.             android:layout_width="200px"
  117.         android:layout_height="wrap_content"
  118.         android:textSize="18dip"
  119.         android:ellipsize="marquee" 
  120.         android:focusable="true" 
  121.         android:marqueeRepeatLimit="marquee_forever" 
  122.         android:focusableInTouchMode="true" 
  123.         android:scrollHorizontally="true"
  124.         android:text="文字滚屏文字跑马灯效果加长加长加长加长加长加长加长加长加长加长加长加长"
  125.         android:background="#FF0000"
  126.                       android:textColor="#FFFFFF"
  127.         >
  128.     </TextView>
复制代码
最后如果你还是觉得我写的不够详细 看的不够爽 不要紧我把源代码的下载地址贴出来 欢迎大家一起讨论学习
 第四讲TextView.rar (124.02 KB, 下载次数: 553)