2012-04-23 92 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);