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
android


source to share


No one has answered this question yet

See similar questions:

125
How do I create a circular ProgressBar in android?

or similar:

3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
1260
How can I open the url in the Android browser from my application?
879
How do I convert Drawable to Bitmap?
620
How to define circle shape in rendered android xml file?
476
How to programmatically take a screenshot on Android?
424
Can Android graphics directories contain subdirectories?
421
How to change the progress color of a step in Android
363
How to convert Bitmap to Drawable in Android?
five
Run color programmatic transition
0
To change the look



All Articles
Loading...
X
Show
Funny
Dev
Pics