android - How to center vector drawable in layer-list without scaling -
i attempting use vectordrawable
in layerlist
without scaling vector. example:
<layer-list> <item android:drawable="@color/grid_item_activated"/> <item android:gravity="center" android:drawable="@drawable/ic_check_white_48dp"/> </layer-list>
the drawable ic_check_white_48dp
id defined as:
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="48dp" android:height="48dp" android:viewportwidth="24.0" android:viewportheight="24.0"> <path android:fillcolor="#ffffffff" android:pathdata="m9,16.17l4.83,12l-1.42,1.41l9,19 21,7l-1.41,-1.41z"/> </vector>
the desired effect check icon centered in layer drawable, without scaling. issue is, layer-list above causes check icon scaled fit layer size.
i can produce desired effect if replace vector drawable pngs each density , modify layer-list such:
<layer-list> <item android:drawable="@color/grid_item_activated"/> <item> <bitmap android:gravity="center" android:src="@drawable/ic_check_white_48dp"/> </item> </layer-list>
is there way can using vectordrawable
?
i ran same problem trying center vectors drawables on layered list.
i have workaround, not same works, need set size entire drawable , add padding vector item:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <size android:height="120dp" android:width="120dp"/> <solid android:color="@color/grid_item_activated"/> </shape> </item> <item android:top="24dp" android:bottom="24dp" android:left="24dp" android:right="24dp" android:drawable="@drawable/ic_check_white_48dp"/> </layer-list>
the size of shape above sets size of entire drawable, 120dp in example, padding on second item, 24dp in example, centers vector image.
its not same using gravity="center"
working way of using vectors in api 21 , 22.
Comments
Post a Comment