-1
我正在製作鎖屏,我想顯示幀動畫顯示電池充電,但動畫不顯示,所有日誌都打印。我嘗試過使用處理程序也開始動畫,但沒用。我的代碼非常冗長,所以我在下面添加相關的代碼。無法啓動幀動畫
在代碼創建:在功能
//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);
}
你應該在''else''中做''return''嗎?否則,你最終會用''i = 0''調用''setBackgroundResource''? – harism