Shape Drawable Size not working
For me, setting the gravity of the item to "center" solved the issue.For example:
<item android:id="@android:id/progress" android:gravity="center"> <clip> <shape> <size android:height="2dp"/> <solid android:color="@color/my_color"/> </shape> </clip></item>
It can work with a foreground
. It seems like you can't set a background's gravity. But you can on a foreground. I checked API 21, 23 and 24 (well, with the Studio design preview) and the following places a solid circle dot on the ImageView.
<shape android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/colorPrimary" /> <size android:height="8dp" android:width="8dp" /></shape>
With the layout snippet
<ImageView android:foreground="@drawable/list_new_dot" android:foregroundGravity="right|center_vertical" tools:src="@drawable/model_1_sm" />
UPDATE: While it appears to work in the layout design tool, it doesn't look the same in the emulator. UPDATE 2: Since this answer has a few votes, you might want to check what I actually used in order to show a new indicator dot:https://gist.github.com/CapnSpellcheck/4d4638aefd085c703b9d990a21ddc1eb
Just to specify the user983447's answer - the size attribute does really mean a proportion. You should set the size for all shapes in your layer-list and it'll be used a as a proportion when scaling - like the layout_weight
attribute of LinearLayout
. So it's better to name it not a size
but a weight
Below is a work-around how to implement top and bottom white lines without using the size
attribute:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <solid android:color="#fff" /> </shape> </item> <item android:top="1dp" android:bottom="1dp"> <shape> <solid android:color="#888" /> </shape> </item></layer-list>