Как использовать рисованную анимацию при нажатии кнопки - PullRequest
0 голосов
/ 22 апреля 2019

Я пробовал много кодов здесь, но ничего не получалось и там просто нет учебных пособий, как использовать рисованная анимация при нажатии кнопки.

Но НИЧЕГО сработало.

Я пробовал это:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/pressed" />
    <item android:state_pressed="false" android:drawable="@drawable/lostpressd" />
</selector>

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/e1" android:duration="50" />
    <item android:drawable="@drawable/e2" android:duration="50" />
    and so on 

и потерянный пресс в обратном порядке.

1 Ответ

0 голосов
/ 22 апреля 2019

Я решил вашу проблему:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/image1" android:state_pressed="true" />
    <item android:drawable="@drawable/image2" android:state_pressed="false" />
</selector>

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item
        android:drawable="@drawable/image1"
        android:duration="200" />
    <item
        android:drawable="@drawable/image2"
        android:duration="200" />
    <item
        android:drawable="@drawable/image3"
        android:duration="200" />
</animation-list>

в вашей деятельности:

 final ImageView img = (ImageView) findViewById(R.id.my_img);
    img.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            img.setBackgroundResource(R.drawable.anim);
            AnimationDrawable animationDrawable = (AnimationDrawable) img.getBackground();
            animationDrawable.setVisible(true, true);
            animationDrawable.start();

        }
    });
...