Textview Marquee 在棒棒糖版本中不滚动

Textview Marquee not scrolling in lollipop version

我有文本视图的选取框,它在棒棒糖之前的版本中可以顺利滚动。但不能在棒棒糖版本及更高版本中使用。请帮我解决这个问题。

以下是 XML.

的代码
   <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:id="@+id/textView1"
    android:layout_gravity="center_horizontal"
    android:ellipsize="marquee"
    android:singleLine="true"
    android:layout_marginTop="-12dp"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:textColor="@color/white"
    android:background="#00AEEF"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:fadingEdge="horizontal"
    android:freezesText="true"
   />

scrollbars = "horizontal" 水平,scrollbars = "vertical" 垂直。

尝试使用以下代码

android:maxLines = "AN_INTEGER"
android:scrollbars = "horizontal"

创建一个 MyTextView 扩展 TextView 然后覆盖 isFocus()

public class MyTextView extends TextView {

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

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() {
    //always focus  
    return true;
}
}

然后使用

  <common.widget.MyTextView
    android:id="@+id/tv_autoplay"
    android:background="#CDC9C4"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:focusableInTouchMode="true"
    android:focusable="true"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:textColor="#fff"
    android:gravity="center"
    android:text="marqueemarqueemarqueemarqueemarqueemarquee……………………"
    android:layout_width="match_parent"
    android:layout_height="30dp" />