Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>EDIT</h2> <p>If i understood well what you are trying to do, substitute your code with this:</p> <p>CustomizeDialog.java</p> <pre><code>import android.app.Dialog; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.view.WindowManager; import android.widget.Button; import android.widget.ImageView; public class CustomizeDialog extends Dialog { Button okButton; ImageView imageAnim = null; Bitmap bm; Context ctx; AnimationDrawable frameAnimation; public CustomizeDialog(Context context) { super(context); ctx = context; } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); WindowManager.LayoutParams params = getWindow().getAttributes(); params.x = 30; params.height = 500; params.width = 500; params.y = 50; getWindow().setAttributes(params); setContentView(R.layout.test); frameAnimation = new AnimationDrawable(); frameAnimation.addFrame(ctx.getResources().getDrawable(R.drawable.fb1), 1000); frameAnimation.addFrame(ctx.getResources().getDrawable(R.drawable.fb2), 1000); frameAnimation.addFrame(ctx.getResources().getDrawable(R.drawable.fb3), 1000); frameAnimation.addFrame(ctx.getResources().getDrawable(R.drawable.fb4), 1000); // set false for loop animation frameAnimation.setOneShot(false); imageAnim = (ImageView) findViewById(R.id.img); imageAnim.setBackgroundDrawable(frameAnimation); imageAnim.post(new Starter()); } class Starter implements Runnable { public void run() { frameAnimation.start(); } } } </code></pre> <p>text.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Gallery animated" /&gt; &lt;ImageView android:id="@+id/img" android:layout_width="154dp" android:layout_height="217dp" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>This code show a dialog in which 4 images are loaded every second (in loop). It works. By the way, there were a lot of problems with your code.</p> <p>1) First of all, you have to put variable reference to xml layout after setContentView and not before!</p> <p>2) you can't cast <em>AnimationDrawable</em> to <em>BitmapDrawable</em> when you did <em>AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground()</em></p> <p>3) I don't understand why you tried to set <em>img.setImageBitmap(bm)</em> with a NULL bitmap variable (<em>bm</em> was never set).</p> <p>4) You have to initialize contentView in onCreate method, not in CustomDialog constructor.</p> <p>5) You have to use Thread for not stopping UI loading. If you put animation loop inside code dialog creation, dialog can be stopped and shown not correctly.</p> <p>Hope this help you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload