API Demos 2.3 學習筆記 (6)-- Text->Marquee
更多精彩內容,請點擊閱讀:《API Demos 2.3 學習筆記》
1、默認不處理
android:singleLine="true" android:ellipsize="none"
2、省略號放在起始
android:singleLine="true" android:ellipsize="start"
3、省略號放在中間
android:singleLine="true" android:ellipsize="middle"
4、省略號放在結束
android:singleLine="true" android:ellipsize="end"
5、跑馬燈效果
android:focusable="true" android:focusableInTouchMode="true" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever"
注:1、android:singleLine="true"表示單行顯示。
2、在設置跑馬燈效果時候,最好加上android:focusable="true"和android:focusableInTouchMode="true",分別表示可以獲得焦點,和在觸摸模式下可以獲得焦點。
3、android:marqueeRepeatLimit表示跑馬燈效果重複顯示的次數,隻能取值marquee_forever和正整數。取值marquee_forever時,表示跑馬燈效果一直重複顯示。
下麵我們進行實例代碼解析:
res-value-string.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="marquee_default">This use the default marquee animation limit of 3</string> <string name="marquee_once">This will run the marquee animation once</string> <string name="marquee_forever">This will run the marquee animation forever</string> </resources>
res-layout-marquee.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 默認跑馬燈效果 --> <Button android:layout_width="150dip" android:layout_height="wrap_content" android:text="@string/marquee_default" android:singleLine="true" android:ellipsize="marquee"/> <!-- 跑馬燈效果,重複播放一次 --> <Button android:layout_width="150dip" android:layout_height="wrap_content" android:text="@string/marquee_once" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="1"/> <!-- 跑馬燈效果,一直重複播放 --> <Button android:layout_width="150dip" android:layout_height="wrap_content" android:text="@string/marquee_forever" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever"/> </LinearLayout>
src-com.example.android.apis.text-Marquee.java
package com.example.android.apis.text; import com.example.android.apis.R; import android.app.Activity; import android.os.Bundle; public class Marquee extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //將marquee布局文件渲染出一個View對象,並作為Activity的默認View setContentView(R.layout.marquee); } }
效果預覽:
最後更新:2017-04-02 06:51:58