android课程第一节(TextView控件使用)

TextView控件使用

一、TextView基本使用(创建方式)

  1、在程序中创建TextView对象

如下代码:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView tv = new TextView(this);
        tv.setText("你好!");
        setContentView(tv);
    }

  2、在xml布局中使用

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

 二、TextView属性

  设置字体的大小推荐使用sp作为单位

  设置宽度或者高度等属性时推荐使用dp(dip)作为单位

 三、设置超链

  android:autoLink设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接,可选值(none/web/email/phone/map/all)

  如下代码:

TextView
        android:id="@+id/tv"
        android:autoLink="phone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:textColor="#00FF00"
        android:text="欢迎大家收看《Android开发教程》系列课程。感谢大家的支持。\n我的博客: http://www.cnblogs.com/564085444java\n我的电话:18681463111" />

四、跑马灯效果

  android:ellipsize设置当文字过长时,该控件该如何显示。有如下值设置:start-省略号显示在开头;end-省略号显示在结尾;middle-省略号显示在中间;marquee-以跑马灯的方式显示(动画横向移动)

  android:marqueeRepeatLimit在ellipsize指定marquee的情况下,设置重复滚动的次数,当设置为marquee_forever时表示无限次。

  android:focusabileInTouchMode:是否在触摸模式下获得焦点

  android:focusable控件是否能够获取焦点

代码如下:

<TextView
        android:id="@+id/tv"
        android:autoLink="phone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:focusable="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:focusableInTouchMode="true"
        android:textSize="20sp"
        android:textColor="#00FF00"
        android:text="欢迎大家收看《Android开发教程》系列课程。感谢大家的支持。\n我的博客: http://www.cnblogs.com/564085444java\n我的电话:1868146311" />

 

posted @ 2015-07-05 10:42  简简-单单  阅读(201)  评论(0编辑  收藏  举报