2012-04-23 77 views
1

我有以下属性一个TextView:安卓的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。但是我想在启动活动时自动滚动它。我怎样才能做到这一点 ?

+0

“自动滚动它”你指的是在这里选取框? – waqaslam 2012-04-23 07:29:45

+0

你可以定义“滚动”更多?因为如果你想让它滚动TextView中的文本,你会遇到问题,因为你已经把它放在singleLine =“true”上。 – Loyalar 2012-04-23 07:30:29

+0

让我检查我给出的答案吧,试试吧 – Khan 2012-04-23 08:14:47

回答

1

默认TextView当选取焦点时,选框效果起作用。要制作自动选框效果,您需要扩展TextView类。请参阅link以供参考。

2
<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"/> 
+0

'singleLine =“true”'将导致代码无法工作。 – Si8 2013-08-16 21:09:42

1

set android:scrollHorizontally="true"用于该textview。

还设置以下两个属性:

text.setMovementMethod(new ScrollingMovementMethod()); 

text.setSelected(true);