Android:TextView不会自动滚动

Android:TextView不会自动滚动,android,textview,Android,Textview,我有一个具有以下属性的TextView: <TextView android:id="@+id/appheader" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerVertical="true" android:textColor="#ffffff" a

我有一个具有以下属性的TextView:

<TextView
        android:id="@+id/appheader" 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_centerVertical="true"
        android:textColor="#ffffff"
        android:layout_marginLeft="3dp"
        android:textSize="21sp"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:focusable="true"
        android:focusableInTouchMode="true"/> 


实际上,只有当我单击TextView时,TextView才会滚动。但我想在启动活动时自动滚动它。我怎样才能做到这一点呢?

默认情况下
TextView
marquee效果在获得焦点时起作用。要实现自动选框效果,需要扩展
TextView
类。见此参考

默认情况下,
TextView
字幕效果在获得焦点时有效。要实现自动选框效果,需要扩展
TextView
类。见此参考


<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="very long text to srollll dkfjadkfjkldjfkjdkghjhtudhfjhdjfkdfkadjsajekdfjak" 
    android:singleLine="true" 
    android:marqueeRepeatLimit="marquee_forever" 
    android:ellipsize="marquee"
    android:focusable="true" 
    android:focusableInTouchMode="true"/>

为该文本视图设置android:ScrollHorizontal=“true”

同时设置以下两个属性:

text.setMovementMethod(new ScrollingMovementMethod());

text.setSelected(true);

为该文本视图设置android:scrollHorizontally=“true”

同时设置以下两个属性:

text.setMovementMethod(new ScrollingMovementMethod());

text.setSelected(true);

“自动滚动”你指的是字幕吗?你能给“滚动”下更多的定义吗?因为如果你想让它在TextView中的文本中滚动,你会遇到一个问题,因为你把它放在了singleLine=“true”上。在你的活动中,你使用了TextView TextView tv=(TextView)findViewById(R.id.appheader);tv.setSelected(true);让你检查一下我给你的答案,它是有效的。试试看,如果我们设置singleLine=“true”,为什么文本不会滚动。它对我有用。“自动滚动”你指的是字幕吗?你能给“滚动”下更多的定义吗?因为如果你想让它在TextView中的文本中滚动,你会遇到一个问题,因为你把它放在了singleLine=“true”上。在你的活动中,你使用了TextView TextView tv=(TextView)findViewById(R.id.appheader);tv.setSelected(true);让你检查一下我给你的答案,它是有效的。试试看,如果我们设置singleLine=“true”,为什么文本不会滚动。这对我有用。