您的位置:首页 > 产品设计 > UI/UE

使TextView组件的android:ellipsize="marquee"属性生效

2014-02-27 14:44 831 查看
由于TextView默认情况下是获取不到焦点的,即便设置android:focusable="true",也是没有获取到焦点的。

解决办法:自定义UI

1.创建一个类继承TextView,实现3个构造方法。

2.覆写isFocused()方法,让它的返回值为true。(这样就能欺骗系统,自定义的控件也就能获取到焦点了)

3.在布局文件中不要使用TextView,而是使用自定义类(全路径)。

自定义UI

package com.xxc.mobilesafe.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

public class FocusedTextView extends TextView {

public FocusedTextView(Context context) {
super(context);
}

public FocusedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public FocusedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

/**
* 欺骗系统,让系统认为FocusedTextView得到了焦点了
*/
public boolean isFocused() {
return true;
}
}

布局文件

<com.xxc.mobilesafe.ui.FocusedTextView
android:focusable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:text="123456789asdasdasofieowijfof8dureu04nrf"
/>


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: