2011-01-31 21 views

Respuesta

109

Hay varios, dependiendo del tipo de flasheo que quiera decir. Puede, por ejemplo, usar animación alfa e iniciarla cuando su botón aparezca por primera vez. Y cuando el usuario hace clic en el botón, en su OnClickListener simplemente haga clearAnimation().

Ejemplo:

public void onCreate(Bundle savedInstanceState) { 
    final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible 
    animation.setDuration(500); // duration - half a second 
    animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate 
    animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely 
    animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in 
    final Button btn = (Button) findViewById(R.id.your_btn); 
    btn.startAnimation(animation); 
    btn.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(final View view) { 
      view.clearAnimation(); 
     } 
    }); 
} 
+2

Alex: gracias por la solución rápida. Estoy aprendiendo Android con mi primera aplicación y no había llegado a la animación, lo haré ahora. – ron

+0

¿Esto también funcionará con un elemento del menú? Si es así, ¿podría preguntar cómo? – wizurd

11

Puede utilizar este código y, así como también puede decidir el momento abrir y cerrar de botón a través de mAnimation.setDuration (200);. El código es el siguiente.

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    select=(Button)findViewById(R.id.bSelect); 
    Animation mAnimation = new AlphaAnimation(1, 0); 
    mAnimation.setDuration(200); 
    mAnimation.setInterpolator(new LinearInterpolator()); 
    mAnimation.setRepeatCount(Animation.INFINITE); 
    mAnimation.setRepeatMode(Animation.REVERSE); 
    select.startAnimation(mAnimation); 
    select.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      v.clearAnimation(); 


     } 
    }); 

} 
+1

Hombre impresionante ... Gracias por sus maravillosos esfuerzos. –

+3

¿cuál es la diferencia con la respuesta aceptada? ctrl + c, ctrl + v –

+0

Gustavo, ¿Hiciste tu trabajo? Si es así, entonces disfruta, no tomes estrés innecesario. :) –

Cuestiones relacionadas