我将此xml图层列表定义为progressDrawable:
<item android:id="@android:id/background"
android:useLevel="false">
<shape
android:innerRadius="@dimen/product_widget_progress_bar_inner_radius"
android:shape="ring"
android:thickness="@dimen/product_widget_progress_bar_thickness_normal"
android:useLevel="false" >
<solid android:color="@color/transparent" />
</shape>
</item>
<item android:id="@android:id/progress" >
<shape
android:innerRadius="@dimen/product_widget_progress_bar_inner_radius"
android:shape="ring"
android:thickness="@dimen/product_widget_progress_bar_thickness_normal" >
<solid android:color="@color/blue" />
</shape>
</item>
这里的问题是我需要直径可变(与屏幕尺寸成比例)。
所以我尝试以编程方式绘制它。到目前为止,我已经做到了这一点:
GradientDrawable background = new GradientDrawable();
background.mutate();
background.setShape(GradientDrawable.RING);
background.setColor(Color.TRANSPARENT);
background.setUseLevel(false);
GradientDrawable progress = new GradientDrawable();
progress.mutate();
progress.setShape(GradientDrawable.RING);
progress.setColor(Color.BLUE);
progress.setUseLevel(false);
ClipDrawable clipDrawable = new ClipDrawable(progress, Gravity.LEFT,
ClipDrawable.HORIZONTAL);
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] {
clipDrawable, background });
但我无法控制戒指的直径或厚度。 任何想法我怎么能解决这个问题?