Android學習筆記——TextView+跑馬燈

TextView:文本框。顯示文本的組件。
一、使用TextView實現多行顯示

設置相關屬性:
android:lines="x",設置顯示的行數,x爲任意非0整數,如4;
android:singleLine="true",設置爲單行顯示;
android:ellipsize="none",設置文本超出範圍時,省略號的位置,可選值有none,start,middle,end和marquee,分別表示不顯示省略號,顯示在文本左邊,顯示在文本中間,顯示在文本右邊和使用跑馬燈效果;

多行顯示:

<TextView 
	    android:id="@+id/textView1"
	    android:layout_width="match_parent"
	    android:layout_height="wrap_content"
	    android:lines="4"
	    android:text="【多行顯示】《掃毒》講述以馬昊天爲首的毒品調查科,與手下張子偉和臥底蘇建秋在執行一次跨國大型掃毒行動中,被毒犯巨頭八面佛識破後遭遇反埋伏,最終全軍覆沒的故事。影片分別在中國香港、澳門地區以及泰國取景,重頭戲主要在泰國,包括出動軍用直升機、潛入鱷魚潭,以及大量的爆破和動作場面等。陳木勝稱,《掃毒》是一部比自己以往所有作品更狠、更寫實的動作片。"
	    android:ellipsize="end"/>



二、使用TextView實現跑馬燈效果
實現跑馬燈效果,必須添加以下屬性:
android:singleLine="true",單行顯示;
android:ellipsize="marquee",開啓跑馬燈效果;
android:focusable="true",獲取焦點;
android:focusableInTouchMode="true",觸摸模式下獲取焦點;
android:marqueeRepeatLimit="marquee_forever",循環播放;


佈局如下:

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:text="我是1989年5月初3早晨九點多出生的,請問在2016年運勢怎麼樣?" />

運行效果:



三、爲文本添加超鏈接
android:autoLink="web",連接到網頁;
android:autoLink="phone",連接到撥號界面;
android:autoLink="email",連接到email應用程序;
android:autoLink="map",連接到谷歌地圖(設備必須安裝谷歌地圖);
android:autoLink="all",匹配以上所有鏈接;
android:autoLink="none",不添加任何超鏈接;

代碼:

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="www.baidu.com"
        android:autoLink="web"
         />
運行效果:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章