フレーム アニメーション - FrameAnimation
アニメーション効果を形成するために、一連の画像を再生します。その本質は、画像自体として使用できる一連の画像のコレクションである Drawable です。
1. Drawable フォルダーの下に、animation-list をルート ノードとするリソース ファイル (drawable_anim) を作成します。
<animation-list android :oneshot= "false" >
<item android :drawable= "@mipmap/progress_1" android :duration= "50" />
<item android :drawable= "@mipmap/progress_2" android :duration= " 50" />
<item android :drawable= "@mipmap/progress_3" android :duration= "50" />
<item android :drawable= "@mipmap/progress_4" android :duration= "50"/> </
アニメーションリスト>
oneshot: 1 回だけ再生するかどうか
drawable: フレームによって参照される画像
duration: 1 フレームの再生時間
2. imageview で背景を設定 ( R.layout.anim_drawable_dialog_layout )
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android :layout_width= "match_parent" android :layout_height= "match_parent" > <ImageView android :id= "@+id/refreshing_drawable_img " android :layout_width= "wrap_content" android :layout_height= "wrap_content" android :layout_centerInParent= "true" android :scaleType= "fitCenter" android :src= "@drawable/drawable_anim"/> </RelativeLayout>
3. AlertDialog を継承してスタイルを設定する
画像のanimationDrawableを取得する(progressImg.getDrawable())
画像が背景に設定されている場合 (progressImg.getBackground())
animationDrawable.start、アニメーション開始
public class AnimDrawableAlertDialog extends AlertDialog { private ImageView progressImg ; //帧动画 private AnimationDrawable animation ; public AnimDrawableAlertDialog (Context context) { super ( context , R.style.MyDialog ) ; } @Override protected void onCreate (バンドル savedInstanceState) { super .onCreate(savedInstanceState) ; setContentView( R.layout.anim_drawable_dialog_layout ) ; // imageviewの外側の領域 をクリックすると、アニメーションは消えませんsetCanceledOnTouchOutside( false ) ; progressImg = (ImageView) findViewById(R.id. refresh_drawable_img ) ; //アニメーション リソースをロードします animation = (AnimationDrawable) progressImg .getDrawable() ; } / ** * AlertDialogのonStart()ライフサイクル で開始アニメーションを実行*/ @Override protected void onStart () { super .onStart() ; animation .start() ; } /** * AlertDialogのonStop()ライフサイクルで停止アニメーションを実行 */ @Override protected void onStop () { super .onStop() ; animation .stop() ; } }
4. ダイアログ スタイルを設定する ( R.style.MyDialog )
<resources> <!--カスタムダイアログの背景を境界線なしで完全に透明にする--> <style name= "MyDialog" parent= "android:style/Theme.Dialog" > <!--背景の色と透明度--> <item name = "android:windowBackground" > @android:color/transparent </item> <!--タイトルを削除するかどうか--> <item name= "android:windowNoTitle" > true </item> <!--削除するかどうかボーダー--> <item name= "android:windowFrame" > @null</item> <!--アクティビティの上に浮かんでいるかどうか--> <item name= "android:windowIsFloating" > true </item> <!--ぼやけているかどうか--> <item name= "android: backgroundDimEnabled" > false </item> </style> </resources>
5. アクティビティでダイアログ ボックスを呼び出す
AnimDrawableAlertDialog progressDrawableAlertDialog = new AnimDrawableAlertDialog( this ) ; progressDrawableAlertDialog.show() ;
6.効果