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