放入/ RES你的gif图片/原始文件夹
在你的类声明mProgressDialog
TransparentProgressDialog mProgressDialog;
然后使用下面的代码,以显示进度对话框
if (mProgressDialog == null)
mProgressDialog = new TransparentProgressDialog(this);
if (mProgressDialog.isShowing())
mProgressDialog.dismiss();
mProgressDialog.setTitle(getResources().getString(R.string.title_progress_dialog));
mProgressDialog.setCancelable(false);
mProgressDialog.show();
创建一个类TransparentProgressDialog,其中.gif可以使用Glide库加载。
public class TransparentProgressDialog extends Dialog {
private ImageView iv;
public TransparentProgressDialog(Context context) {
super(context, R.style.TransparentProgressDialog);
WindowManager.LayoutParams wlmp = getWindow().getAttributes();
wlmp.gravity = Gravity.CENTER_HORIZONTAL;
getWindow().setAttributes(wlmp);
setTitle(null);
setCancelable(false);
setOnCancelListener(null);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
iv = new ImageView(context);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(iv);
Glide.with(context).load(R.raw.gif_loader).into(imageViewTarget);
layout.addView(iv, params);
addContentView(layout, params);
}
@Override
public void show() {
super.show();
}
}
您能找到解决方案吗? – 2015-04-06 11:49:27
Android不支持git图像。您必须在Drawable文件夹中使用不同的图像并为它们设置动画。 请遵循以下问题: - [link](http://stackoverflow.com/questions/19900747/custom-progress-dialog-with-squre-image-rotation-with-asyntask) – 2015-04-08 11:01:27
如果您需要再次使用gif文件,我建议你使用[this](http://abhinavasblog.blogspot.in/2014/04/animated-gif-imageview-library-for.html)库,而不是使用多个图像。这太简单和高效。 :) – 2015-04-08 11:14:28