如何在Android中创建具有可绘制进度和背景项的自定义进度条? 这是我的来源
<style parent="@android:style/Widget.ProgressBar" name="customProgressBar">
<item name="android:indeterminateDrawable">@drawable/ic_refresh_white</item>
</style>
<ProgressBar
android:id="@+id/pdWithImage"
android:layout_width="50dp"
android:layout_height="50dp"
style="@style/customProgressBar"
android:layout_centerInParent="true" />
我添加了png图像背景,但当我运行我的应用程序progresbar不旋转 我怎么能解决我的问题?
答案 0 :(得分:0)
class ProgressDialog extends Dialog {
private ImageView iv;
public ProgressDialog(Context context, int resourceIdOfImage) {
super(context, R.style.YourStyle);
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.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
iv = new ImageView(context);
iv.setImageResource(resourceIdOfImage);
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(3000);
iv.setAnimation(anim);
iv.startAnimation(anim);
}
}
用这样的图像调用这个ProgressDialog方法
ProgressDialog(activity, R.drawable.image)
希望它可以帮助你:)