Answer the question
In order to leave comments, you need to log in
How to animate ImageButton in Android Studio?
How to animate an ImageButton when it is clicked?
In the res/anim folder, I created the animation_button.xml file :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="250"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />
<scale
android:duration="200"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.8"
android:toYScale="0.8" />
</set>
final Animation animButton = AnimationUtils.loadAnimation(this, R.anim.animation_button);
ImageButton btnStart = (ImageButton) this.findViewById(R.id.btnStart);
btnStart.setOnClickListener(onClickListener);
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnStart:
btnStart.startAnimation(animButton);
break;
........................................
}
}
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question