Alert Dialog with custom Gif image

4

I would like to know how to create a custom Alert Dialog where you have an ImageView containing a GIF.

In my Main.

imgAndroid = (Button) findViewByid (R.id.imagandroid);
imgAndroid.setBackgroundResource (R.drawable.imagee);

anime = (AnimationDrawable) imgAndroid.getBackground;
anime.start();

Create a Drawable

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
    <item android:drawable="@drawable/play" android:duration="1000" />
    <item android:drawable="@drawable/playum" android:duration="1000" />
    <item android:drawable="@drawable/playdois" android:duration="1000"/>
    <item android:drawable="@drawable/playtres" android:duration="1000"/>
    <item android:drawable="@drawable/playquatro" android:duration="1000"/>
    <item android:drawable="@drawable/playcinco" android:duration="1000"/>

</animation-list>

The code of my Alert Dialog

 public void testedialog (View View){
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.dialoggif);
    //button que leva para o menu
    Button irum = (Button) dialog.findViewById(R.id.button111);
    irum.setOnClickListener(new android.view.View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setContentView(R.layout.menu);
            dialog.dismiss();
        }
    });
    //button que manda para o proximo nivel

    Button dialogButton = (Button) dialog.findViewById(R.id.button122);
    dialogButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setContentView(R.layout.menu);
            dialog.dismiss();

        }
    });


    dialog.show();

}
    
asked by anonymous 28.12.2016 / 19:31

1 answer

3

According to the google documentation, you should not put "anime.start ()" inside the onCreate () , you should use onWindowFocusChanged that will run when your app is in the user's focus.

According to them:

  

It's important to note that the start () method called on the AnimationDrawable can not be called during the onCreate () method of your Activity, because the AnimationDrawable is not fully attached to the window. If you want to play the animation immediately, without requiring interaction, then you might want to call it from the onWindowFocusChanged () method in your Activity, which will get called when Android brings your window into focus.

Follow the link for reference: link

    
28.12.2016 / 22:10