【问题标题】:unable to start frame animation无法启动帧动画
【发布时间】:2012-10-08 17:50:55
【问题描述】:

我正在制作锁屏,我想显示显示电池充电的帧动画,但没有显示动画并且打印了所有日志。我也尝试使用处理程序启动动画但没有用。我的代码很长,所以我在下面添加相关代码。

创建代码:

//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

标签: android frame android-animation


【解决方案1】:

使用下面的代码来启动动画。

AnimationDrawable mAnimDrawable=(AnimationDrawable)battery_ImgView.getBackground();
mAnimDrawable.start();

让我知道它是否有效。

【讨论】:

    猜你喜欢
    • 2019-12-03
    • 1970-01-01
    • 2016-01-03
    • 1970-01-01
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多