Make an ImageView blink

0

My app has ImagemView and I'm trying to make it blink. This method repeats for 6 seconds.

@Override
public void onSensorChanged(SensorEvent event) {
    verificarAndamento();

    if(emCaputura){
        Log.e("Tempo" , ""+tempoDecorrido);
        if(tempoDecorrido % 1000==0){
            imagem.setVisibility(View.INVISIBLE);
            //Toast.makeText(this, "1000", Toast.LENGTH_SHORT).show();

        }else if(tempoDecorrido % 500==0){
            imagem.setVisibility(View.VISIBLE);

          //Toast.makeText(this, "500", Toast.LENGTH_SHORT).show();
        }//Jeito que tentei fazer repedir

        synchronized (this) {
            long current_time = event.timestamp;

            curX = event.values[0];
            curY = event.values[1];
            curZ = event.values[2];

            if (prevX == 0 && prevY == 0 && prevZ == 0) {
                last_update = current_time;
                last_movement = current_time;
                prevX = curX;
                prevY = curY;
                prevZ = curZ;
            }

            long time_difference = current_time - last_update;
            if (time_difference > 0) {
                float movement = Math.abs((curX + curY + curZ) - (prevX - prevY - prevZ)) / time_difference;
                int limit = 1500;
                float min_movement = 1E-6f;
                if (movement > min_movement) {
                    if (current_time - last_movement >= limit) {   
                        movements.add(movement);
                    }
                    last_movement = current_time;
                }
                prevX = curX;
                prevY = curY;
                prevZ = curZ;
                last_update = current_time;
            }
        }
    }
}

I want the image to flicker while the method is running.

    
asked by anonymous 05.11.2014 / 16:38

1 answer

2

Use this:

flicker.xml

<?xml version="1.0" encoding="utf-8"?>
<set
  xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:duration="500" android:repeatCount="infinite" android:repeatMode="reverse" android:fromAlpha="0.5" android:toAlpha="1.0" />
</set>

In the code, do this:

imageView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.flicker));

Set how many times you want to repeat the animation. In this case, it is android:repeatCount="infinite"

As you wish for 6 seconds, put in android:duration="6000 "

    
05.11.2014 / 16:54