L
L
likeh8r2015-02-10 00:08:47
Android
likeh8r, 2015-02-10 00:08:47

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>

In the OnCreate() function I wrote
final Animation animButton = AnimationUtils.loadAnimation(this, R.anim.animation_button);
ImageButton btnStart = (ImageButton) this.findViewById(R.id.btnStart);
btnStart.setOnClickListener(onClickListener);

And put a handler on the OnClick event :
View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btnStart:
                    btnStart.startAnimation(animButton);
                    break;
........................................
            }
        }
    };

But as a result, when you click on the button, an application error occurs. What could be the problem and how to implement this task correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
troffee, 2015-02-10
@troffee

better make images of buttons of two types, large and small. You can also change colors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question