Background style not showing in progress bar

I am trying to do something like this:

enter image description here

This is what my code does:

enter image description here

I have this code in my accessible file:

progress_bar_layout.xml

<?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 android:innerRadius="70dp" android:shape="ring" android:thickness="18dp"> </shape> </item> <item android:id="@android:id/progress"> <shape android:innerRadius="70dp" android:shape="ring" android:thickness="18dp"> <gradient android:endColor="#ff0f315f" android:startColor="#ff005563" android:type="sweep" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <shape android:innerRadius="70dp" android:shape="ring" android:thickness="18dp"> <gradient android:endColor="#ff1490e4" android:startColor="#ff00c0dd" android:type="sweep" /> </shape> </item> </layer-list> 

layout:

  <ProgressBar android:id="@+id/bar" style="?android:attr/progressBarStyleHorizontal" android:layout_width="180dp" android:layout_height="180dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:max="100" android:progress="99" android:progressDrawable="@drawable/progress_bar_layout" android:secondaryProgress="30" /> 

The problem is that my background style is not displayed. This is why I use progress to do the background work, but as you can see, this does not work very well bcs, the maximum size is 99, and there is space at the end. Am I missing code?

+5
source share
1 answer

Basically, I had to split the progress_bar_layout.xml graphic file for each element, so one file with progress settings and another for background settings. And then I added them to the corresponding elements.

  android:background="@drawable/circle_shape" android:progressDrawable="@drawable/circular_progress_bar" /> 

Using a list of layers, the project did not find the background settings, so this approach solved my problem.

circle_shape.xml

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="60dp" android:shape="ring" android:thickness="10dp" android:useLevel="false"> <solid android:color="@color/blue"></solid> </shape> 

circular_progress_bar.xml

 <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="270" android:toDegrees="270"> <shape android:innerRadius="60dp" android:shape="ring" android:thickness="10dp" android:useLevel="true"> <solid android:color="@color/blue"></solid> </shape> </rotate> 
+3
source

All Articles