0

I have tried to set the image of an imagebutton to my drawable xml file. I don't know why it doesn't work. My drawable xml:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@drawable/mad_frame1"
        android:duration="700"/>
    <item
        android:drawable="@drawable/mad_frame2"
        android:duration="700"/>

    <!--etc. frames 1-24 -->

</animation-list>

In my fragment xml:

<ImageButton
    android:id="@+id/c_mad"
    android:layout_width="match_parent"
    ndroid:layout_height="210dp"
    android:adjustViewBounds="false"
    android:background="?android:selectableItemBackground"
    android:contentDescription="@string/mad_thumb"
    android:cropToPadding="false"
    android:scaleType="centerInside" />

My code:

public void onViewCreated(View view, Bundle savedInstanceState) {
    ImageButton madButton = (ImageButton) getView().findViewById(R.id.c_mad);
    btnList.add(madButton);

    madButton.setBackgroundResource(R.drawable.mad_anim);
    ((AnimationDrawable)madButton.getBackground()).start();
}

I am currently creating these animation xml's myself. Is there any way to use a gif drawable instead? I think it would work with an AnimatedImageDrawable, but thats only for API level 28 (i only have 26).

1 Answers1

1

You can take reference of given third party weblink : I think this may help you , you can give a try by taking reference from there -

  • The Animation i am trying to use is like a gif though (multiple independent frames). I'm not trying to animate the ImageButtons values. – ShiranaiDev Nov 27 '19 at 15:16