Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Fade view in and out

I need to display an image button that fades in and out (and in and out and so on...) The transparency can be set with setAlpha but how can I fade in and out? I mean I cannot do it on another thread because you need to do such things on the UI thread, right?

I guess it can be done with animations but I haven't found anything, because I don't have any experience with animations and don't really know what to search for...

Actually what I really want is to fade one image in and another one out but I guess the easiest way is to place the first image button below the second and just fade the second one. Or is there an easier way to do it?

like image 682
DominicM Avatar asked May 28 '13 20:05

DominicM


People also ask

What is fade in and fade out in Android?

In android, Fade In and Fade Out animations are used to change the appearance and behavior of the objects over a particular interval of time. The Fade In and Fade Out animations will provide a better look and feel for our applications.

How do you make a view visible and invisible on Android?

use setVisibility method. for hiding button you can use button. setVisibility(View. GONE);.. you can use View.

What is Alpha animation in Android?

An animation that controls the alpha level of an object. Useful for fading things in and out. This animation ends up changing the alpha property of a Transformation.


1 Answers

Here is the solution I'm using now, that works on API level lower than 12:

AlphaAnimation anim = new AlphaAnimation(1.0f, 0.0f); anim.setDuration(1000); anim.setRepeatCount(NUM_REPEATS); anim.setRepeatMode(Animation.REVERSE); button.startAnimation(anim); 
like image 78
DominicM Avatar answered Sep 28 '22 06:09

DominicM