Android 我可以将所有TextView设置为marquee吗?

Android 我可以将所有TextView设置为marquee吗?,android,eclipse,textview,marquee,Android,Eclipse,Textview,Marquee,我有6个文本视图,我希望他们在同一时间字幕所有 <TextView android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true"/> <TextView android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMo

我有6个文本视图,我希望他们在同一时间字幕所有

 <TextView
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"/>

 <TextView
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true">
但它总是使我的应用程序崩溃

请尝试以下操作:- 我希望它能帮助你……:)


基于android SDK 2.3.3的测试

  • 文本视图布局如下所示:

    <TextView
    android:id="@+id/txt1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:singleLine="true"
    android:text="I have 6 textviews and I want them to marquee all at the same time"     />
    

  • 只需将这些参数放在您的文本视图中:
    android:singleLine=“true”android:ellipsize=“marquee”android:marqueeRepeatLimit=“marquee\u forever”android:scroll横向=“true”android:focusableInTouchMode=“true”android:focusableInTouchMode=“true”
    它只适用于一个textView。只有一个正在滚动另一个未滚动我也测试了txt2。setSelected(true)但它会使我的应用程序崩溃
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <TextView
            android:id="@+id/TextView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:marqueeRepeatLimit="marquee_forever"
            android:padding="5dip"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="Hello World" />
    
        <TextView
            android:id="@+id/TextView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/TextView1"
            android:ellipsize="marquee"
            android:marqueeRepeatLimit="marquee_forever"
            android:padding="5dip"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="Testing!!!" />
    
    </RelativeLayout>
    
        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     Animation animationToLeft = new TranslateAnimation(400, -400, 0, 0);
            animationToLeft.setDuration(12000); 
            animationToLeft.setRepeatMode(Animation.RESTART);
            animationToLeft.setRepeatCount(Animation.INFINITE);
    
            Animation animationToRight = new TranslateAnimation(-400,400, 0, 0);
            animationToRight.setDuration(12000); 
            animationToRight.setRepeatMode(Animation.RESTART);
            animationToRight.setRepeatCount(Animation.INFINITE);
    
            TextView tv = (TextView) findViewById(R.id.TextView02);
            TextView tv1 = (TextView) findViewById(R.id.TextView03);
    
            tv.setAnimation(animationToLeft);
            tv1.setAnimation(animationToRight);
    
    
            String textLeft = "Really Long Scrolling Text Goes Here.... ..... ............ .... ....";
            String textRight = "Testing";
    
            tv.setText(textLeft);
            tv1.setText(textRight);
    }
    
    <TextView
    android:id="@+id/txt1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:singleLine="true"
    android:text="I have 6 textviews and I want them to marquee all at the same time"     />
    
    TextView txt1 = (TextView)this.findViewById(R.id.txt1);
    txt1.setSelected(true);
    txt1.setTextColor(Color.WHITE);
    ... ...