我想在对话框中显示自定义动画,而不是在对话框中显示常规动画。
以下是我的布局 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 是否附加到窗口?