Below is a very basic and simple form of implementation. Remembering that to create an animation, it depends a lot on creativity. So if you want to do crazy things, you have to do a lot of research. In the code example below, a ImageView
is created in which after the click will appear another two ImageButton
in the sequence, which would be a btnFotoGaleria
and another btnFotoCamera
.
public class ActivityMain extends Activity{
ImageView btnFotoPerfil;
ImageButton btnFotoGaleria;
ImageButton btnFotoCamera;
// Animação
Animation animFadein;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnFotoGaleria= (ImageButton) findViewById(R.id.btnFotoGaleria);
btnFotoCamera= (ImageButton) findViewById(R.id.btnFotoCamera);
// load the animation
animFadein = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_in);
btnFotoPerfil= (ImageView) findViewById(R.id.btnFotoPerfil);
// evento onclick no botao
btnFotoPerfil.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnFotoGaleria.setVisibility(View.VISIBLE);
btnFotoCamera.setVisibility(View.VISIBLE);
// start the animation
btnFotoGaleria.startAnimation(animFadein);
btnFotoCamera.startAnimation(animFadein);
}
});
}
}
It's important to remember to set up the parameters of ImageButton
by setting android:visibility="gone"
so that they remain invisible until the user clicks.
Within res
you need to create a directory named anim
and a .xml
for your animation, for example fade_in.xml
with the following code below:
fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
</set>
Details