TextView自定义跑马灯效果

来源:互联网 发布:淘宝评分怎么提高 编辑:程序博客网 时间:2024/04/29 11:57

在复杂的布局中想要使用跑马灯效果需要自己自定义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"    />

0 0
原创粉丝点击