HI I am developing an application for Android. In my activity it contains one Linear layout. I want to set the ring type background. So I use the following code.
?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="2.7"
android:shape="ring"
android:thickness="16dp"
android:useLevel="false" >
<solid android:color="#EEEEEE" />
</shape>
It is working fine. Now I want to change the thickness in above code programmatically. How can I change this? I did R&D for that but didn't get answer.
Changing the thickness programmatically may be involved. The answers to the question Creating ring shape in Android code provide some insight.
If you simply want to scale up or scale down the thickness of the ring proportionally as the display size increases/decreases as you mention in the comments, then you may want to consider using the android:thicknessRatio
or the android:innerRadiusRatio
attribute in your XML to do so and delete the android:thickness
attribute. See the documentation for details.
I hope this helps.
I got the another way.
?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="2.7"
android:shape="ring"
android:thickness="@dimensions/thickness_of_circle"
android:useLevel="false" >
<solid android:color="#EEEEEE" />
And i create Different values folder for different screens . Like
values-sw720dp 10.1” tablet 1280x800 mdpi
values-sw600dp 7.0” tablet 1024x600 mdpi
values-sw480dp 5.4” 480x854 mdpi
values-sw480dp 5.1” 480x800 mdpi
values-xhdpi 4.7” 1280x720 xhdpi
values-xhdpi 4.65” 720x1280 xhdpi
values-hdpi 4.0” 480x800 hdpi
values-hdpi 3.7” 480x854 hdpi
[![enter image description here][1]][1]
values-mdpi 3.2” 320x480 mdpi
values-ldpi 3.4” 240x432 ldpi
values-ldpi 3.3” 240x400 ldpi
values-ldpi 2.7” 240x320 ldpi
Define the thickness according to screen size in the dimension file of all the values folder it will automatically take the file according to screen size.
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