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

时间:2016-07-14 05:45:09

标签: java android xml android-5.0-lollipop marquee

我有文本视图的选框,并且可以顺利地滚动前棒棒糖版本。但不能在棒棒糖版本及以上版本中使用。请帮帮我。

以下是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"
   />

2 个答案:

答案 0 :(得分:0)

横向为

scrollbars = "horizontal",垂直为scrollbars = "vertical"

尝试使用以下代码

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

答案 1 :(得分:0)

创建一个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" />