我有6个textviews,我希望它们同时在所有文本中显示
<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);
但它总是崩溃我的应用
答案 0 :(得分:0)
试试这个: - 我希望它会帮助你.......)
<?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);
}
答案 1 :(得分:0)
基于android SDK 2.3.3进行测试
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" />
为每个textview设置属性:
TextView txt1 = (TextView)this.findViewById(R.id.txt1);
txt1.setSelected(true);
txt1.setTextColor(Color.WHITE);
... ...