添加一個TextView 來實現跑馬燈效果。
android:focusable="true" //允許TextView獲取焦點
android:ellipsize="marquee" //以橫向滾動方式顯示 要獲取焦點之前
android:marqueeRepeatLimit="marquee_forever" //滾動的次數
android:focusableInTouchMode="true" //是否在觸摸的模式下獲得焦點
android:scrollHorizontally="true" //啓動水平滾動條
android:singline="true" //字在一行顯示
在TextView中添加這些屬性
然後在Java文件中要添加
TextView textView = (TextView)this.findViewById(R.id.textview); //把TextView關聯進來
String content="如果天黑之前來得及,我要忘了你的眼睛"; //這是要顯示的話語
//設置文本顏色
textView.setTextColor(Color.BLUE);
//設置文本大小
textView.setTextSize(20);
//設置文本顯示
textView.setText(content);