动画在Android的状态栏 [英] Animation in status bar in Android

查看:271
本文介绍了动画在Android的状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid系统。我想作的电池充电动画的在手机中,例如,在屏幕的右上角,小图标正在充电时,移动倒置,并停止在当前电池百分比。

I'm new here in Android. I'd like to make a Battery Charging Animation in the phone, for example, in the top-right of the screen, the small icon that is moving upside down when charging and stops on a current battery percentage.

到目前为止,在我的code,我已经能够让它动,但它永远不会停止。

So far in my code, I've been able to make it move, but it never stops.

我要的是为动画时无法充电或停止其停止在当前电池百分比。

What I want is for the animation to stop when it is not charging or for it to stop on a current battery percentage.

下面是我的code动画:

Here is my code in the animation :

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.batteryinfo);

        ImageView batteryImage = (ImageView) findViewById(R.id.BatteryImage);
        batteryImage.setBackgroundResource(R.drawable.ic_battery_animation);

        BatteryAnimation = (AnimationDrawable) batteryImage.getBackground();
        batteryImage.post(new Starter());

        textBatteryLevel = (TextView) findViewById(R.id.batterylevel_text);

        registerBatteryLevelReceiver();
    }

    class Starter implements Runnable {

        public void run() {
            BatteryAnimation.start();
        }

    }

到目前为止,我可以得到电池状态的插头类型,以及电池的健康。

So far, I can get the Battery Status, the Plug Type, and the Health of the Battery.

推荐答案

入门级应该也实现了停逻辑。 是这样的:

Starter class should implement also stop logic. Something like:

class Starter implements Runnable {
    boolean stopConditionMet = false;
    public void run() {
        BatteryAnimation.start();
        try {
         while (!stopConditionMet) { Thread.sleep(500); } 
        } catch (InterruptedException e) {}
         BatteryAnimation.stop();

    }
    public void stop() { stopConditionMet=true; }

}

(而不是忙等待你可以用wait()的做到这一点 - notifyAll的()方案上面的例子,如果为简单起见)

(instead of busy wait you can do this with wait()-notifyAll() scheme. The above example if for simplicity).

......,你会需要保持入门类的实例的活动中。匿名声明它不会让你当你需要改变它的值。

.. and you'll need to keep the instance of the Starter class inside your Activity. Declaring it anonymously won't allow you to change its value when you need.

这篇关于动画在Android的状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆