多个图片循环播放的进度条

来源:互联网 发布:熊猫加速器for mac 编辑:程序博客网 时间:2024/05/02 09:46

实现方法从网上找的代码,记录下来方便自己查看

第一步,在style文件中添加

<!--自定义进度条-->    <style name="CustomDialog" parent="@android:style/Theme.Dialog">        <item name="android:windowFrame">@null</item>        <item name="android:windowIsFloating">true</item>        <item name="android:windowContentOverlay">@null</item>        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>        <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>    </style>    <style name="CustomProgressDialog" parent="@style/CustomDialog">        <item name="android:windowBackground">@android:color/transparent</item>        <item name="android:windowNoTitle">true</item>    </style>

anim/loading.xml

<?xml version="1.0" encoding="utf-8"?><animation-list android:oneshot="false"    xmlns:android="http://schemas.android.com/apk/res/android">    <item android:duration="150" android:drawable="@mipmap/loading1"/>    <item android:duration="150" android:drawable="@mipmap/loading2"/>    <item android:duration="150" android:drawable="@mipmap/loading3"/>    <item android:duration="150" android:drawable="@mipmap/loading4"/>    <item android:duration="150" android:drawable="@mipmap/loading5"/>    <item android:duration="150" android:drawable="@mipmap/loading6"/>    <item android:duration="150" android:drawable="@mipmap/loading7"/>    <item android:duration="150" android:drawable="@mipmap/loading8"/>    <item android:duration="150" android:drawable="@mipmap/loading9"/>    <item android:duration="150" android:drawable="@mipmap/loading10"/>    <item android:duration="150" android:drawable="@mipmap/loading11"/>    <item android:duration="150" android:drawable="@mipmap/loading12"/></animation-list>

自定义dialog/LoadingDialog

public class LoadingDialog extends Dialog {    private Context context = null;    private static CustomProgressDialog customProgressDialog = null;    public LoadingDialog(Context context){        super(context);        this.context = context;    }    public LoadingDialog(Context context, int theme) {        super(context, theme);    }    public static LoadingDialogcreateDialog(Context context){        loadingDialog= new LoadingDialog(context,R.style.CustomProgressDialog);        loadingDialog.setContentView(R.layout.layout_progessbar);        loadingDialog.getWindow().getAttributes().gravity = Gravity.CENTER;        return customProgressDialog;    }    public void onWindowFocusChanged(boolean hasFocus){        if (customProgressDialog == null){            return;        }        ImageView imageView = (ImageView) loadingDialog.findViewById(R.id.progress_img);        AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();        animationDrawable.start();    }}

调用方法:

LoadingDialog dialog = LoadingDialog .createDialog(this);dialog.show();dialog.dismiss();
0 0