Marquee在Android中不滚动

时间:2012-11-21 05:30:31

标签: android marquee

我想在我的Android应用程序中使用marquee的功能,并使用此代码来实现目标:

 <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);

我不知道为什么它不起作用。我经历了很多相关的帖子,但还没找到解决方案。请帮帮我。谢谢。

3 个答案:

答案 0 :(得分: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>

答案 1 :(得分:3)

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

是唯一必需的属性,滚动甚至适用于layout_weight定义的layout_width=0dp

这是一些示例代码:

<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应该被选中您已经在代码中完成了。

希望它会帮助你。

答案 2 :(得分:1)

尝试

android:singleLine="true"

而不是

android:lines="1"

它将解决您的问题。