HardBirch

TextView文本滚动显示效果控件TextSwitcher【已解决】

时间:13-09-22 栏目:安卓技术篇 作者:张飞不张,文采横飞 评论:0 点击: 3,701 次

问题:如题所示;

解决方法:

        // LOTTERY INFO
tsLotteryInfoContent[0] = (TextSwitcher) findViewById(R.id.lottery_info_content_01);
tsLotteryInfoContent[1] = (TextSwitcher) findViewById(R.id.lottery_info_content_02);
tsLotteryInfoContent[2] = (TextSwitcher) findViewById(R.id.lottery_info_content_03);

for (int i = 0; i < tsLotteryInfoContent.length; i++) {
tsLotteryInfoContent[i].setFactory(new ViewFactory() {
@Override
public View makeView() {
TextView tv = new TextView(GameHallActivity.this);
tv.setTextColor(getResources().getColor(R.color.lotter_info_text));
return tv;
}
});

tsLotteryInfoContent[i].setInAnimation(AnimationUtils.loadAnimation(
getApplicationContext(),
R.anim.push_down_in));
tsLotteryInfoContent[i].setOutAnimation(AnimationUtils.loadAnimation(
getApplicationContext(),
R.anim.push_down_out));
}
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
mHandler.obtainMessage(MSG_WHAT_UPDATE_LETTORY_INFO).sendToTarget();
}
}, 1, 5000);

 

 

    private final Handler mHandler = new Handler() {

@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_WHAT_UPDATE_LETTORY_INFO:
updateLotteryInfo();
break;

default:
break;
}
}
};

private void updateLotteryInfo() {
for (int i = 0; i < tsLotteryInfoContent.length; i++) {
tsLotteryInfoContent[i].setText(getLotteryInfo());
}
}

 

范例大致如上,感谢使用开源代码 ^_^

o R.anim.XXX.xml补充如下:

push_down_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="-100%p" android:toYDelta="0"
android:duration="1000"/>
</set>

 

push_down_out.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromYDelta="0"
android:toYDelta="100%p" />

 

 

 

 

TextView文本滚动显示效果控件TextSwitcher【已解决】:等您坐沙发呢!

发表评论


QQ群互动

Linux系统与内核学习群:194051772

WP建站技术学习交流群:194062106

魔豆之路QR

魔豆的Linux内核之路

魔豆的Linux内核之路

优秀工程师当看优秀书籍

优秀程序员,要看优秀书!

赞助商广告

友荐云推荐