我正在制作锁屏,我想显示显示电池充电的帧动画,但不显示动画并且打印所有日志。我也尝试使用处理程序启动动画,但没有用。我的代码很长,所以我在下面添加相关代码。
在创建代码:
//battery charging animation
animation = new AnimationDrawable();
animation.addFrame(getResources().getDrawable(R.drawable.charge5), 30);
animation.addFrame(getResources().getDrawable(R.drawable.charge4), 30);
animation.addFrame(getResources().getDrawable(R.drawable.charge3), 30);
animation.addFrame(getResources().getDrawable(R.drawable.charge2), 30);
animation.addFrame(getResources().getDrawable(R.drawable.charge1), 30);
animation.setOneShot(false);//animation plays again
battery_ImgView.setBackgroundDrawable(animation)
检查电池状态的函数中的代码
public void SetBatteryIcon(View paramView, int paramInt,
int plugged, int m) {
int i=0;
int p = m / 4;
if (plugged == 0) {
if (paramInt <= p)
i = R.drawable.battery4;// 1 line
else if (paramInt <= 2 * p && paramInt > p)
i = R.drawable.battery3;// 2 line
else if (paramInt <= 3 * p && paramInt > 2 * p)
i = R.drawable.battery2;// 3line
else
i = R.drawable.battery1;// 4 line full
} else {// charging
Log.i("charging","anim");
animation.start();
}//else
paramView.setBackgroundResource(i);
}