Ring shapes for preview L not working

Just by testing the new developer preview and noticing that my existing link images are not displaying properly. Instead of a ring, it’s a complete circle. Is this a mistake or has something changed, or am I doing it wrong to get started? Any possible solutions?

here is the code:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@android:id/progress"> <shape android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="7.0"> <solid android:color="#ff5698fb"/> </shape> </item> </layer-list> 

Thank!

Update

I updated the form as follows:

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="7.0"> <solid android:color="#ff5698fb"/> </shape> </item> <item > <shape android:innerRadiusRatio="4" android:shape="ring" android:thicknessRatio="5.5"> <solid android:color="#ffffff"/> </shape> </item> </layer-list> 

which creates a ring by superimposing two circles. But the progress bar in which I use it does not work. Here is the code for the progress bar:

 <ProgressBar android:id="@+id/progressCircle" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:indeterminate="false" android:max="100" android:progress="65" android:rotation="270" android:progressDrawable="@drawable/progress_circle" android:visibility="visible"/> 
+13
android android-5.0-lollipop
Jul 06 '14 at 6:19 06:19
source share
3 answers

You need to add android:useLevel="true" to the progress element. This did not seem necessary in previous versions, but L wants it.

 <item android:id="@android:id/progress"> <shape android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="7.0" android:useLevel="true" > <solid android:color="#ff5698fb"/> </shape> </item> 
+21
Jul 30 '14 at 20:49
source share

TL; DR: explicitly set the useLevel value for all ring shapes used in custom execution steps.




The answer to Kano's question is a way to solve your problem. I am supplementing it to add general information about ring shapes to custom execution strings.

It seems that the default value for useLevel has changed in Android versions. Here is the part of the study related to this.

The following is a working implementation of the progress bar using a ring as a progress indicator and another ring as a progress background:

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Progress background --> <item android:id="@android:id/background"> <shape android:shape="ring" android:useLevel="false"> <solid android:color="#dae1e6"/> </shape> </item> <!-- Progress --> <item android:id="@android:id/progress"> <!-- Rotation of the progress to start at the top--> <rotate android:fromDegrees="-90" android:pivotX="50%" android:pivotY="50%" android:toDegrees="-90"> <shape android:shape="ring" android:useLevel="true"> <solid android:color="#61bcf9"/> </shape> </rotate> </item> </layer-list> 

Using it as progressDrawable in a ProgressBar :

 <ProgressBar style="?android:attr/progressBarStyleHorizontal" android:layout_width="100dp" android:layout_height="100dp" android:progressDrawable="@drawable/custom_horizontal" android:progress="50" android:max="100" android:id="@+id/progressBar" android:layout_gravity="center"/> 

Setting useLevel=true in the form of the run ring and useLevel=false in the form of the background ring gives the correct desired behavior for all versions of Android:

Correct in both versions

Removing useLevel from the background form:

Pre 5.0 (left) | 5.0 (right)

Incorrect in KitKatCorrect in lollipop

Removing useLevel from the execution form:

Pre 5.0 (left) | 5.0 (right)

Correct in kitkatIncorrect in Lollipop




So, as I understand it, useLevel used to indicate whether the progress value affects the form. If it is not (false), it will be completely colored; if it is (true), it will be colored in the same way as the value of progress.

To summarize, it seems that:

  • useLevel is used by default to true in Android <5.0 , forcing the background ring to track the progress value if useLevel not set in its ring shape, which makes it hidden behind the progress bar ring.
  • useLevel is used by default to false in Android> = 5.0 , causing the progress bar to be completely colored if useLevel not set in its ring form.

So, due to this inconsistency, it is better to explicitly set the value of useLevel to true in figures that depend on progress, and to false in those that do not.

This behavior is based on my observations, I have not found a single source confirming it. Android white papers are not very clear ...

+20
Oct 23 '14 at 16:44
source share

I just want to add some links to the frame source code to confirm that useLevel defaults to true in the Android API version <21 (<5.0) and defaults to false in the API version> = 21 (> = 5.0) as Christian Garcia previously stated.

In android-20, the GradientDrawable.java file, line 820-835:

 if (shapeType == RING) { .... st.mUseLevelForShape = a.getBoolean( com.android.internal.R.styleable.GradientDrawable_useLevel, true); } 

In android-21, the GradientDrawable.java file, line 1028-1047:

 if (state.mShape == RING) { .... state.mUseLevelForShape = a.getBoolean( R.styleable.GradientDrawable_useLevel, state.mUseLevelForShape); } 
+1
Oct 18 '15 at 16:17
source share



All Articles