Android 文本视图中自动水平滚动的问题

Android 文本视图中自动水平滚动的问题,android,scroll,textview,chronometer,Android,Scroll,Textview,Chronometer,我想实现自动水平滚动的情况下,如果我的文字太长。当活动是空的,没有任何焦点时,它就工作了。但当我尝试在一个带有计时器的活动中实现这一点时,它不起作用。我在没有计时表的情况下测试了它,它可以工作。我试图使用setSelected(true),但它也不起作用。有没有办法解决这个问题,我需要计时器的滚动功能。如有任何意见和答复,将不胜感激 ScrollTextView.class public class ScrollingTextView extends TextView{ public Scro

我想实现自动水平滚动的情况下,如果我的文字太长。当活动是空的,没有任何焦点时,它就工作了。但当我尝试在一个带有计时器的活动中实现这一点时,它不起作用。我在没有计时表的情况下测试了它,它可以工作。我试图使用
setSelected(true)
,但它也不起作用。有没有办法解决这个问题,我需要计时器的滚动功能。如有任何意见和答复,将不胜感激

ScrollTextView.class

public class ScrollingTextView extends TextView{

public ScrollingTextView(Context context, AttributeSet attrs,
        int defStyle){
    super(context, attrs, defStyle);
}

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

public ScrollingTextView(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;
}
}
TextView

<com.android.app.ScrollingTextView
    android:id="@+id/display_message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:paddingLeft="10dp"
    android:paddingTop="10dp"
    android:singleLine="true"
    android:text="Display Message"
    android:textSize="18dp"
    android:textColor="#ffffff"
    android:ellipsize="marquee"
    android:scrollHorizontally="true"
    android:fadingEdge="horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    android:focusableInTouchMode="true"/>

将其添加到XML中

我自己已经弄明白了

android:focusable="true" 
&然后再试一次

编辑:

我面临这个问题

在我的例子中,这就是Textview不滚动的原因是

我在textview上面放了一个listview,这样textview就不会滚动了。所以我选了这个

设置listview可聚焦为false

listview.setfocusable(false);

然后它工作了,文本正在滚动。

试试这个,它可能会帮助你



但是在我的活动中,我没有listview,我尝试了
.setFocusable(false)”。它不起作用了。
<TextView
            android:id="@+id/textView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:onClick="onClick" 
            android:smoothScrollbar="true"
            android:scrollbars="vertical"
             android:maxLines="6"
            android:ellipsize="none"
            android:scrollHorizontally="false"
            android:singleLine="false"
            />