I´m working on an app wich uses different progress bars, and I want them to look as the ones in Google fit, with rounded cornes. I have a custom drawable for each bar with different colors, and it rounds the outside corners but not the inside corners, as you can see here: My custom drawable is:
<?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>
<corners android:radius="@dimen/progress_bar_rounded" />
<solid android:color="@color/progressbarBackground" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="@dimen/progress_bar_rounded" />
<solid android:color="@color/progressbarGreen" />
</shape>
</clip>
</item>
</layer-list>
An the progress bars code is:
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="@dimen/progress_bar_high"
android:id="@+id/GreenProgressBar"
android:indeterminate="false"
android:layout_marginLeft="15dp"
android:layout_gravity="center_vertical"
android:progressDrawable="@drawable/custom_green_progressbar" />
I could use some libraries as https://github.com/akexorcist/Android-RoundCornerProgressBar , but as it is such a simple thing i think it´s not worth it. I also have been looking on different threads, but nothing has worked for me. Any idea, without having to work with .9.png images, if possible?
Thanks a lot!
You can easily implement a custom progress bar to fit your needs. For example, if you have a solid color background - simply use a foreground 9-path to hide everything but the progress. If you are targeting newer Android Versions you can simply use the built in mask support (not supported in older versions).
How to make the progress bar to be curved as per design? Replace the <clip></clip> element, with <scale android:scaleWidth="100%"></scale>. That will make the shape keep its form as it grows - and not cut off. Unfortunately, it will have a little unwanted visual effect at the beginning - as the shape corners don't have enough space to draw.
Modular - The RoundedProgressBar library can be seamlessly included in custom layouts due to the fact that each corner can have a different radius Additionally, the RoundedProgressBar handles all internal state during configuration changes These are the methods which can be called on the RoundedProgressBar class:
What is use in Android? A linear progress indicator should always fill from 0% to 100% and never decrease in value. It should be represented by bars on the edge of a header or sheet that appear and disappear.
Use the scale
tag rather than clip
:
<?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>
<corners android:radius="@dimen/progress_bar_rounded" />
<solid android:color="@color/progressbarBackground" />
</shape>
</item>
<item android:id="@android:id/progress">
<scale android:scaleWidth="100%" android:useIntrinsicSizeAsMinimum="true">
<shape>
<corners android:radius="@dimen/progress_bar_rounded" />
<solid android:color="@color/progressbarGreen" />
<size android:width="@dimen/progress_bar_rounded"/>
</shape>
</scale>
</item>
</layer-list>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With