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++;
}
}
};




你可能感兴趣的:(Android 头部设置上下滚动的消息列表 TextView (TextSwitcher运用))