UI提出进度条在开始时需要实现一个从0到指定进度的动画递增效果。于是用一个handler实现,代码如下:
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0: //好评率
if(progreessGoodSpeed< (progreessGood*100/allComments)) //判断是否到达指定数值
{
progress_good.setProgress(progreessGoodSpeed);
progreessGoodSpeed=progreessGoodSpeed+1;
handler.sendMessageDelayed(mTimeHandler.obtainMessage(0), 10);//递归延时10ms
}
break;
default:
break;
}
}
};//初始化进度条自增递归
使用时直接初始化processbar与相关数值即可。
allComments =100;//总进度分母
progress_good = (ProgressBar) header.findViewById(R.id.item_comment_header_progress_good);
progreessGoodSpeed = 0;//初始进度
progreessGood = 50;//目标进度
mTimeHandler.sendMessageDelayed(mTimeHandler.obtainMessage(0), 0);