Android自定义类似ProgressDialog效果的Dialog

Android自定义类似ProgressDialog效果的Dialog.

方法如下:

1.首先准备两张自己要定义成哪样子的效果的图片和背景图片(也可以不要背景)。

如我要的效果:



2.定义loading_dialog.xml布局文件(这里你也可以按自己的布局效果定义,关键是要有个imageView):



	
	

3.定义一个loadingDialog中imageView转动的动画:loading_animation.xml



    

4.定义dialog的style.


    


5.写点创建Dialog的代码,你可以自己封装成一个方法。

/**
	 * 得到自定义的progressDialog
	 * @param context
	 * @param msg
	 * @return
	 */
	public static Dialog createLoadingDialog(Context context, String msg) {

		LayoutInflater inflater = LayoutInflater.from(context);
		View v = inflater.inflate(R.layout.loading_dialog, null);// 得到加载view
		LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);// 加载布局
		// main.xml中的ImageView
		ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);
		TextView tipTextView = (TextView) v.findViewById(R.id.tipTextView);// 提示文字
		// 加载动画
		Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
				context, R.anim.load_animation);
		// 使用ImageView显示动画
		spaceshipImage.startAnimation(hyperspaceJumpAnimation);
		tipTextView.setText(msg);// 设置加载信息

		Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);// 创建自定义样式dialog

		loadingDialog.setCancelable(false);// 不可以用“返回键”取消
		loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.FILL_PARENT,
				LinearLayout.LayoutParams.FILL_PARENT));// 设置布局
		return loadingDialog;

	}

最后来张整体的效果图:

Android自定义类似ProgressDialog效果的Dialog_第1张图片








你可能感兴趣的:(Android)