Simple xml clicked animation.
Source: StackOverflow
Question: How to crate a simple clicked animation using xml?
Answer:
Create this one /res/anim/clicked_animation.xml
:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha = "1.0"
android:toAlpha = "0.5"
android:duration = "300">
</alpha>
<scale
android:fromXScale = "1"
android:toXScale = "0.9"
android:fromYScale = "1"
android:toYScale = "0.9"
android:pivotX="50%"
android:pivotY="50%"
android:duration = "50">
</scale>
</set>
Then in your View
just do this:
yourView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation clickedAnimation = AnimationUtils.loadAnimation(v.getContext(), R.anim.clicked_animation);
clickedAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
//do your stuff here
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
v.startAnimation(clickedAnimation);
}
});