Android custom progress bar with .gif file

后端 未结 6 1901
执念已碎
执念已碎 2020-12-20 04:05

In my app i have a custom progress bar

progress.xml

 

        
6条回答
  •  天涯浪人
    2020-12-20 04:43

    Put your gif image in /res/raw folder

    In your class declare mProgressDialog

    TransparentProgressDialog mProgressDialog;
    

    then use following code to show progress dialog

    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();
    

    Create a class TransparentProgressDialog where .gif can be loaded using Glide library.

    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();
    }
    

    }

提交回复
热议问题