Android 头部设置上下滚动的消息列表 TextView (TextSwitcher运用)

private TextSwitcher textView; 

private Animation anim, anim1;

private int index;

private Timer timer;

private int times = 4000;

private void upAndDownControl(){

textView = (TextSwitcher) layout.findViewById(R.id.home_news_textview);


// 定义视图显示工厂,并设置
textView.setFactory(new ViewFactory() {


public View makeView() {
TextView tv = new TextView(HomeActivity.this);
tv.setTextSize(13);
tv.setEllipsize(TruncateAt.END);
tv.setSingleLine(true);
tv.setTextColor(getResources().getColor(R.color.home_black_7a7a7a));
return tv;
}
});


anim = AnimationUtils.loadAnimation(HomeActivity.this, R.anim.down);
anim1 = AnimationUtils.loadAnimation(HomeActivity.this, R.anim.top);
textView.setInAnimation(anim1);
textView.setOutAnimation(anim);
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
mHandler.obtainMessage(HOME_NEWSINFO_SCROLL).sendToTarget();
}
}, 1, times);

}


private  Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
 if (msg.what == HOME_NEWSINFO_SCROLL) {
if (index >= InfoData.size()) {
index = 0;
}
textView.setText(InfoData.get(index).getTitle());
num= InfoData.get(index).getNum();
index++;
}
}
};




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值