-2

I'm trying to create a custom progressBar in my Android app, but I'm stuck in applying the corners on the progress layout.

Here is the intended result: enter image description here

My code is this:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
    <shape>
        <padding
            android:bottom="1dp"
            android:left="1dp"
            android:right="1dp"
            android:top="1dp" />
        <solid android:color="@android:color/white" />
    </shape>
</item>

<item android:id="@android:id/progress" android:gravity="center">
    <clip>
        <shape android:shape="rectangle">
            <corners
                android:bottomRightRadius="20dp"
                android:topRightRadius="20dp" />
            <solid android:color="#026B91" />
        </shape>
    </clip>
</item>

And the layout result from the code: enter image description here

I can't seem to do the round corner from the progress layout, I tried different approaches but nothing works. What am I missing? Thanks

Phantom
  • 877
  • 2
  • 12
  • 28

2 Answers2

-1

Use below drawable as your progressbar drawable.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
    <solid
            android:color="@color/progbar_color" />
    <corners android:radius="60dp"/>
</shape>
</item>

<item
android:id="@android:id/progress">
<clip>
    <shape>
        <solid
            android:color="@color/progbar_track_color" />
        <corners android:radius="60dp"/>
    </shape>
</clip>
</item>

</layer-list>
  • @pskink Thanks, but then do you know another approach on how can I achieve my design? – Phantom Sep 21 '17 at 10:37
  • @pskink Thanks, I tried the one but it doesn't work. Thanks for the other answer also, but I'm trying to do this via XML. I'm still searching for a solution for that. – Phantom Sep 21 '17 at 10:49
-1

Try the below code:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
    <shape>
        <padding
            android:bottom="1dp"
            android:left="1dp"
            android:right="1dp"
            android:top="1dp" />
        <solid android:color="@android:color/white" />
    </shape>
</item>

<item android:id="@android:id/progress" android:gravity="center">
    <clip>
        <shape android:shape="rectangle">
            <corners
                android:radius="0dp"
                android:bottomRightRadius="20dp"
                android:topRightRadius="20dp" />
            <solid android:color="#026B91" />
        </shape>
    </clip>
</item>

My experience is that if you want to set android:bottomRightRadius="20dp" and android:topRightRadius="20dp" you should set android:radius="0dp" also.

John Le
  • 802
  • 7
  • 11