android TextView跑马灯与EditText共存时,犹豫焦点冲突导致的跑马灯失效,有两种解决方案:
1.TextView里设置
android:singleLine="true"//必须用这个 虽然已经过时 但是如果用maxLines=1,跑马灯会失效
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="false"
android:scrollHorizontally="true"
然后再代码中添加:
myTextView.setSelected(true);
2.自定义TextView
/**
* Created by yjc on 2017/5/12.
*/
public class FocusedTextView extends TextView{
public FocusedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public FocusedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FocusedTextView(Context context) {
super(context);
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if(focused)
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
@Override
public void onWindowFocusChanged(boolean focused) {
if(focused)
super.onWindowFocusChanged(focused);
}
@Override
public boolean isFocused() {
return true;
}
}
然后xml直接用就好了:
<com.workinghours.view.FocusedTextView
android:id="@+id/tv_marquee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"vity="center_vertical"
android:singleLine="true"
android:text="0000000000000000000000000000000000000000000000000000"
android:focusable="true"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="marquee_forever"/>