0

通常の進行中のアニメーションダイアログではなく、カスタムアニメーションをダイアログに表示したい。

以下は私のレイアウトXMLファイルです。

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView  
        android:id="@+id/blankImageView"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:background="@anim/loading_anim"/>
</LinearLayout>

DialogのonShowListenerで、私は次のように呼び出しました。

        dialog.setOnShowListener(new DialogInterface.OnShowListener(){

        @Override
        public void onShow(DialogInterface dialog) {
            final ImageView imageView = (ImageView) dlg.findViewById(R.id.blankImageView);
            final AnimationDrawable yourAnimation = (AnimationDrawable) imageView.getBackground();
            yourAnimation.start();
        }

    });

ご覧のとおり、OnShowListenerのダイアログの後にアニメーションを開始しました。ダイアログのonStart()、onCreate()メソッドなどの他のメソッドでアニメーションを開始すると、AnimationDrawableがウィンドウにアタッチされていないため、アニメーションが機能しません。

しかし、onShowListenerインターフェースはAPIレベル8のものです。私の質問は、APIレベル8より前に、AnimationDrawableがウィンドウにアタッチされているかどうかを知る方法はありますか?

4

1 に答える 1

1

onWindowFocusChanged() 関数をオーバーライドして、そこでアニメーションを開始しました。この関数は API レベル 1 から存在するため、すべてのバージョンで魅力的に機能します。

@Override   
public void onWindowFocusChanged(boolean hasFocus){
        ImageView imageView = (ImageView) findViewById(R.id.blankImageView);
        AnimationDrawable yourAnimation = (AnimationDrawable) imageView.getBackground();
        yourAnimation.start();
    }
于 2011-05-26T11:56:56.613 に答える