读书人

AnimationDrawable 在Dialog中不能卡通

发布时间: 2012-07-15 20:11:35 作者: rapoo

AnimationDrawable 在Dialog中不能动画的原因(转)
原来在dialog的onCreate onStart调用的时候UI还没出来 这时候调用动画是不会运行的。

解决办法可以看这里。

http://googlers.iteye.com/blog/907136
其实也就是加一个handler, 让它延时去做

下面是我的LoadingDialog

package com.example;import android.app.Dialog;import android.content.Context;import android.graphics.BitmapFactory;import android.graphics.drawable.AnimationDrawable;import android.os.Bundle;import android.os.Handler;import android.view.Window;import android.view.animation.Animation;import android.widget.ImageView;/** * Created by IntelliJ IDEA. * User: denny * Date: 11-9-27 * Time: 下午3:21 * To change this template use File | Settings | File Templates. */public class LoadingDialog extends Dialog{    private Handler handler = new Handler();    private ImageView iv;    private AnimationDrawable ad;    public LoadingDialog(Context context) {        super(context, android.R.style.Theme_Translucent_NoTitleBar);    }    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        this.requestWindowFeature(Window.FEATURE_NO_TITLE);        setContentView(R.layout.loading_dialog);        iv = (ImageView) findViewById(R.id.loadingImg);        iv.setBackgroundResource(R.drawable.loading);        ad = (AnimationDrawable) iv.getBackground();    }    @Override    public void show() {        super.show();        handler.postDelayed(new Runnable() {            @Override            public void run() {                ad.start();            }        }, 50);    }    @Override    public void dismiss() {        super.dismiss();        ad.stop();    }}

读书人网 >移动开发

热点推荐