【问题标题】:Custom ProgressBar in Android using imageAndroid中使用图像的自定义ProgressBar
【发布时间】:2016-04-18 12:26:02
【问题描述】:

如何在 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 不旋转 我该如何解决我的问题?

【问题讨论】:

    标签: android xml progress-bar android-progressbar


    【解决方案1】:
    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)
    

    希望对你有帮助:)

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    • 1970-01-01
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多