Reputation: 1647
I'm currently working with a drawable to get a ring shaped imageview.
The issue is: I have two of these imageviews in one row all with weight=1, so that they all have the same width. The shape ring drawable's xml tag attribute "innerRadiusRatio" relies on the drawable's width though. So the ring shape will be cropped if the width of the imageview becomes bigger than the height. Is there any way I can make the innerRadiusRatio rely on the height instead of the width? Or even set its scaleType to "fitCenter" or something similar ?
Here's my layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="64dip"
android:layout_width="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/ring_shape_drawable"
android:src="@drawable/test_button_drawable"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/ring_shape_drawable"
android:src="@drawable/test_button_drawable"/>
</LinearLayout>
Here's the shape drawable's xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="2.8"
android:thicknessRatio="30"
android:useLevel="false"
android:shape="ring" >
<solid android:color="@color/custom_red" />
</shape>
And here's the result (with the cropped ringShapeDrawable I don't want):
This would be the desired result:
Thanks for your help :)
Upvotes: 3
Views: 2202
Reputation: 53
Since you're specifying a constant height in the LinearLayout, you should be able to make use of the innerRadius property. You will likely want to switch thicknessRatio to thickness with a set size too.
I've looked at the source for GradientDrawable and there doesn't seem to be an easy way to get it to use the height so if innerRadius isn't suitable, you're probably going to have to wrap each ImageView in another LinearLayout and center it with android:gravity. Doing this would require the drawable to determine the size of the ImageView or specifying it manually, so innerRadius is probably better.
Upvotes: 1
Reputation: 4120
You should get the result you want if you set the height and weight attributes of the ImageViews to wrap_content
.
Upvotes: 0