带图像的自定义进度条

时间:2015-11-25 11:29:40

标签: android android-progressbar

我之前已经问过这个问题,但我花了很多时间试图解释答案却没有成功。

我试图通过图片获得动画循环进度条。 我将此link称为基本理解,但如何创建带图像的自定义进度条..

提前致谢!

1 个答案:

答案 0 :(得分:0)

我创建了一个通过对话框扩展的自定义类。可能这对你有帮助

public class CProgressDialog extends Dialog {

private ImageView iv;

public CProgressDialog(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(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    iv = new ImageView(context);
    iv.setImageResource(R.drawable.spiner_green);
    layout.addView(iv, params);
    addContentView(layout, params); 
}

@Override
public void show() {
    super.show();
    RotateAnimation anim = new RotateAnimation(0.0f, 360.0f,
            Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF,
            .5f);
    anim.setInterpolator(new LinearInterpolator());
    anim.setRepeatCount(Animation.INFINITE);
    anim.setDuration(2000);
    iv.setAnimation(anim);
    iv.startAnimation(anim);
}