2012-11-21 52 views
4

我想用字幕的功能在我的Android應用程序進行滾動和正在使用此代碼爲實現這一目標:跑馬燈在android系統

<TextView 
    android:id="@+id/marqueetext" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:ellipsize="marquee" 
    android:fadingEdge="horizontal" 
    android:lines="1" 
    android:marqueeRepeatLimit="marquee_forever" 
    android:scrollHorizontally="true" 
    android:text="hello all how are you" 
    android:textColor="#ff4500" 
    /> 

MarqueeText = (TextView)ShowTheMessages.this.findViewById(R.id.marqueetext); 
     MarqueeText.setSelected(true); 

我不知道爲什麼它不working.I有經歷了許多相關的職位,但沒有找到解決辦法。請幫助我。提前感謝。

+0

請幫助別人。 – user1726619

回答

8

變化這條線,並嘗試...

android:text="hello all how are you hello all how are you hello all how are you hello all how are you" 
TextView txtView=(TextView) findViewById(R.id.marqueetext); 
txtView.setSelected(true); 

<TextView 
    android:id="@+id/marqueetext" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:ellipsize="marquee" 
    android:fadingEdge="horizontal" 
    android:lines="1" 
    android:marqueeRepeatLimit="marquee_forever" 
    android:scrollHorizontally="true" 
    android:text="hello all how are you hello all how are you hello all how are you hello all how are you" 
    android:textColor="#ff4500" 
    /> 

或另一個例子是...

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView 
     android:id="@+id/marqueetext" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:lines="1" 
     android:ellipsize="marquee" 
     android:fadingEdge="horizontal" 
     android:marqueeRepeatLimit="marquee_forever" 
     android:scrollHorizontally="true" 
     android:textColor="#ff4500" 
     android:text="hello all how are you hello all how are you hello all how are you hello all how are you hello all how are you" /> 
</RelativeLayout> 
+2

這裏設置的文本很長....我可以得到較小文本的選取框嗎? –

3
android:singleLine="true" 
android:ellipsize="marquee" 

是唯一必需的屬性,甚至滾動與layout_width=0dp

這裏定義layout_weight作品是一些示例代碼:

<TextView 
      android:id="@+id/scroller" 
      android:singleLine="true" 
      android:ellipsize="marquee" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="#FFFFFF" 
      android:text="Some veryyyyy long text with all the characters that cannot fit in screen, it so sad :(that I will not scroll" 
      android:layout_marginLeft="4dp" 
      android:layout_weight="3" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      /> 

,但最重要的是的TextView應該得到選擇那你已經完成了你的代碼。

希望它能幫助你。

+0

我已經添加了重要的屬性,甚至現在它不工作。 – user1726619

+0

你有沒有添加android:layout_width =「0dp」android:layout_weight =「3」? –

1

嘗試

android:singleLine="true" 

,而不是

android:lines="1" 

這將解決您的問題。

+0

感謝它的工作。但是,從XML它被棄用,我用TextView.setSingleLine(true)來代替。非常感謝 –