您的位置:首页 > 其它

TextView自定义跑马灯效果

2016-07-05 14:17 435 查看
在复杂的布局中想要使用跑马灯效果需要自己自定义TextView,因为有可能在复杂的布局中原来的TextView获取不到焦点,就不会有效果

解决方法:

自己重写TextView:

public class MarqueeTextView extends TextView {

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

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

public MarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
public boolean isFocused() {
return true;
}
}

<***.MarqueeTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:text="234254fadfadffadfadfgfhdgfhjhfjhfjhjfhjfhjfhjfhjtyteytryetaaaa"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="@color/white"
android:ellipsize="marquee"
android:focusableInTouchMode="true"
android:focusable="true"
/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: