
TextView Marquee Demo
1. 設定TextView
當你想要TextView以一行的方式來顯示文字,可是有的文字太長無法全部顯示,這時可以指定TextView的相關屬性讓過長的文字以跑馬燈的方式顯示。<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/txtMarquee"
android:text="這是文字過長跑馬燈測試,看到請回答,OVER~~"
android:textSize="30sp"
android:marqueeRepeatLimit="-1"
android:ellipsize="marquee"
android:singleLine="true"
android:padding="5sp"
android:focusableInTouchMode="true"
android:focusable="true" />
</LinearLayout>2. 屬性說明
- android:marqueeRepeatLimit="-1"
跑馬燈的循環次數,-1表示無限循環。 - android:singleLine="true"
指定TextView以單行顯示。 - android:focusableInTouchMode="true"
指定在觸控模式下取得焦點,連同下一個focusable都必須設為true,跑馬燈才會動。 - android:focusable="true"
讓TextView可以取得焦點。 - android:ellipsize="marquee"
過長文字的省略方式,共有5種。
none:不作用。形同end。
start:省略開頭文字,注重顯示尾端文字。
middle:省略中間文字,前後文字中間以...呈現。
end:省略尾端文字。
marquee:跑馬燈模式。
0 回應:
張貼意見