更多精彩内容,请点击阅读:《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:android="http://schemas.android.com/apk/res/android"
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);
}
}
效果预览:
欢迎大家关注我的微信公众号:
微信公众号:sn0wdr1am