How can I create this list of layers for circular progress, accessible programmatically

I have this xml layer list defined as my 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>

      

The problem is that I need the diameter to be variable (proportional to the screen size).

So I tried to do it programmatically. So far I have done this:

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

      

But I cannot control the diameter or thickness of the ring. Any ideology how can I solve this?

+3


source to share





All Articles