自定义progressdialog加载动画,这里还有旋转的加载条,美团,多个图片动画

来源:互联网 发布:剧本编写软件 编辑:程序博客网 时间:2024/04/24 13:13

自定义progressdialog加载动画,这里还有旋转的加载条,美团,多个图片动画

下载Demo:http://download.csdn.net/detail/menglele1314/8775497


public class MainActivity extends Activity {    private Button submit;    private AnimationDrawable fightnimation, fightnimationab;    private ImageView pb, net, netab;    private Dialog mLoading;    private Animation animation;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);        setContentView(R.layout.activity_main);        submit = (Button) findViewById(R.id.btn_login_submit);                pb = (ImageView) findViewById(R.id.iv_failure);        animation = AnimationUtils.loadAnimation(MainActivity.this,                R.anim.cirle);        animation.setInterpolator(new LinearInterpolator());        netab = (ImageView) findViewById(R.id.iv_netab);        netab.setBackgroundResource(R.anim.fight);        fightnimationab = (AnimationDrawable) netab.getBackground();        net = (ImageView) findViewById(R.id.iv_net);        net.setBackgroundResource(R.anim.loading);        fightnimation = (AnimationDrawable) net.getBackground();        submit.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View arg0) {                mLoading = createLoadingDialog(MainActivity.this);                mLoading.show();//                mLoading.dismiss();                pb.startAnimation(animation);                fightnimationab.start();                fightnimation.start();            }        });    }
    /**     * 得到自定义的progressDialog     *     * @param context     * @return     */    public static Dialog createLoadingDialog(Context context) {        LayoutInflater inflater = LayoutInflater.from(context);        View v = inflater.inflate(R.layout.layout_loading_dialog, null); // 得到加载view        LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view); // 加载布局        ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);        Animation animation = AnimationUtils.loadAnimation(                context, R.anim.cirle); // 加载动画        animation.setInterpolator(new LinearInterpolator());        spaceshipImage.startAnimation(animation); // 使用ImageView显示动画        Dialog loadingDialog = new Dialog(context, R.style.loading_dialog); // 创建自定义样式dialog        // loadingDialog.setCancelable(false);// 不可以用"返回键"取消        loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(                LinearLayout.LayoutParams.WRAP_CONTENT,                LinearLayout.LayoutParams.WRAP_CONTENT));        return loadingDialog;    }}


下载Demo:点击打开链接

0 0
原创粉丝点击