簡體   English   中英

我可以將所有文本視圖設置為字幕嗎?

[英]can i set all textviews to marquee?

我有6個文本視圖,我希望它們同時字幕

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

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

可能嗎?

TextView txt2 = (TextView)findViewById(r.id.TextView2)
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);
}

基於android SDK 2.3.3的測試

  1. TextViews的布局如下:

     <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" /> 
  2. 為每個textview設置屬性:

     TextView txt1 = (TextView)this.findViewById(R.id.txt1); txt1.setSelected(true); txt1.setTextColor(Color.WHITE); ... ... 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM