放入/ 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