Question

J'ai mes outils de classe dessinables. J'ai besoin de le redessiner périodique pour obtenir un effet de "clignotement". J'utilise TIMER.Schedule pour planifier des invalidésf () mais rien ne s'est produit.

private class DrawableImpl extends Drawable {
    private boolean blinkFlag = false;
    private Timer timer = new Timer(false);

    private int maxFlashCount = 21;
    private int intervalBetweenFlashesInMs = 100;
    private int currentFlashNumber = 0;

    @Override
    public void draw(Canvas canvas) {
        Log.i(TAG, "draw");

        /*draw stable part*/

        if (blinkFlag ) {
            Log.i(TAG, "blink");
            /*draw bliking part*/
        }

        blinkFlag = !blinkFlag;

        final DrawableImpl drawableImpl = this; 
        if (currentFlashNumber < maxFlashCount) {
            Log.i(TAG, "schedule");
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Log.i(TAG, "run from back");
                            drawableImpl.invalidateSelf();
                        }
                    });
                }
            }, intervalBetweenFlashesInMs);
            currentFlashNumber++;
        }
    }
}

En journal quelque chose comme ça
02-08 23: 07: 44.791: info / (258): Draw
02-08 23: 07: 44.791: info / (258): clignotement
02-08 23: 07: 44.791: info / (258): calendrier
02-08 23: 07: 45.011: info / (258): courez à partir de l'arrière
02-08 23: 07: 45.021: info / (258): Draw
02-08 23: 07: 45.021: info / (258): calendrier
02-08 23: 07: 45.171: info / (258): courez à partir de l'arrière
02-08 23: 07: 45.171: info / (258): Draw
02-08 23: 07: 45.171: info / (258): clignotement
02-08 23: 07: 45.171: info / (258): calendrier
02-08 23: 07: 45.331: info / (258): courez à partir de l'arrière

Pourquoi ça n'a pas fonctionné? Dois-je utiliser d'autres méthodes pour cela?

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top