Alert Dialog personalized with GIF image

Asked

Viewed 339 times

4

I would like to know how to create a Alert Dialog customized where you had an Imageview containing a GIF.

On my Main.

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

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

I created 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();

}
  • You can post the layout code dialoggif? And what is the problem that is occurring?

  • Application at error start and is not executed.

  • Can post some description of the error?

1 answer

3


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

According to them:

It’s Important to note that the start() method called on the Animationdrawable cannot be called During the onCreate() method of your Activity, because the Animationdrawable is not yet 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 to reference: https://developer.android.com/guide/topics/graphics/drawable-animation.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.