Hello Android folks,
We've been using selectors and xmls whenever we wanted to apply click effect to the views. Here is very simple and short way to achieve the same.
We can use Android's AnimationUtils class to load the animation on any view.
Below is the sample code which loads the fade_in animation on views which are being clicked:
@Override
public void onClick(View v) {
v.startAnimation(loadAnimation(this, android.R.anim.fade_in));
if(v.getId()==R.id.userImage)
{
}
else if(v.getId()==R.id.nextButton)
{
}
}
Also, import AnimationUtil calss like:
import static android.view.animation.AnimationUtils.loadAnimation;
It serves the purpose in almost all circumstances and keeps us from writing selectors and xmls for so many views.
Thanks
0 Comment(s)