问一下,对于XListView的 XListViewHeader .ava ,需要添加 个 相似跑马灯的效果,
也就是 图片每个一段时间的切换。
本人是在这个位置 设置timer的: 但是 这个timer只要下拉刷新完,就可以cancel的。但是
timer .cancel();这个应该放在什么位置呢?
public class XListViewHeader extends LinearLayout {
public void setState(int state) {
if (state == mState) return ;
if (state == STATE_REFRESHING) { // 鏄剧ず杩涘害
mArrowImageView.clearAnimation();
mArrowImageView.setVisibility(View.INVISIBLE);
//mProgressBar.setVisibility(View.VISIBLE);
mActionImageView.setVisibility(View.VISIBLE);
//timer.schedule(mActionTimerTask,0,100);
} else { // 鏄剧ず绠ご鍥剧墖
mArrowImageView.setVisibility(View.VISIBLE);
//mProgressBar.setVisibility(View.INVISIBLE);
mActionImageView.setVisibility(View.INVISIBLE);
// timer.cancel();
}
switch(state){
case STATE_NORMAL:
if (mState == STATE_READY) {
mArrowImageView.startAnimation(mRotateDownAnim);
}
if (mState == STATE_REFRESHING) {
mArrowImageView.clearAnimation();
}
mHintTextView.setText(R.string.xlistview_header_hint_normal);
timer = new Timer();
mActionTimerTask = new ActionTimerTask();
timer.schedule(mActionTimerTask,0,100);
break;
}
private class ActionTimerTask extends TimerTask { //使用timertask
public void run() {
Message message = new Message();
message.what = 1;
mHandler.sendMessage(message);
}
}
private final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
if(i ==mDrawableIds.length){
i = 0;
}
mActionImageView.setImageResource(mDrawableIds[i]); //切换图片
i++;
break;
default:
break;
}
super.handleMessage(msg);
}
};
也就是 图片每个一段时间的切换。
本人是在这个位置 设置timer的: 但是 这个timer只要下拉刷新完,就可以cancel的。但是
timer .cancel();这个应该放在什么位置呢?
public class XListViewHeader extends LinearLayout {
public void setState(int state) {
if (state == mState) return ;
if (state == STATE_REFRESHING) { // 鏄剧ず杩涘害
mArrowImageView.clearAnimation();
mArrowImageView.setVisibility(View.INVISIBLE);
//mProgressBar.setVisibility(View.VISIBLE);
mActionImageView.setVisibility(View.VISIBLE);
//timer.schedule(mActionTimerTask,0,100);
} else { // 鏄剧ず绠ご鍥剧墖
mArrowImageView.setVisibility(View.VISIBLE);
//mProgressBar.setVisibility(View.INVISIBLE);
mActionImageView.setVisibility(View.INVISIBLE);
// timer.cancel();
}
switch(state){
case STATE_NORMAL:
if (mState == STATE_READY) {
mArrowImageView.startAnimation(mRotateDownAnim);
}
if (mState == STATE_REFRESHING) {
mArrowImageView.clearAnimation();
}
mHintTextView.setText(R.string.xlistview_header_hint_normal);
timer = new Timer();
mActionTimerTask = new ActionTimerTask();
timer.schedule(mActionTimerTask,0,100);
break;
}
private class ActionTimerTask extends TimerTask { //使用timertask
public void run() {
Message message = new Message();
message.what = 1;
mHandler.sendMessage(message);
}
}
private final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
if(i ==mDrawableIds.length){
i = 0;
}
mActionImageView.setImageResource(mDrawableIds[i]); //切换图片
i++;
break;
default:
break;
}
super.handleMessage(msg);
}
};
解决方案
30
建议使用不同的刷新方式