4

Gostaria de saber como criar um Alert Dialog personalizado onde tivesse uma ImageView contendo um GIF.

Na minha Main.

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

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

Criei um 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>

O codigo do meu 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();

}
3
  • Pode postar o código do layout dialoggif? E qual é o problema que está ocorrendo?
    – E.Thomas
    28/12/2016 às 18:39
  • Aplicação ao iniciar da erro e não chega a ser executada.
    – sergiopm
    28/12/2016 às 18:54
  • Pode postar alguma descrição do erro?
    – E.Thomas
    28/12/2016 às 18:54

1 Resposta 1

3

Segundo a documentação do google, você não deveria colocar o "anime.start()" dentro do onCreate(), você deveria usar onWindowFocusChanged que será executado quando sua app estiver no foco do usuário.

De acordo com eles:

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.

Segue o link para referência: https://developer.android.com/guide/topics/graphics/drawable-animation.html

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .