layer-list
Android text in drawable layer-list
One way to add Texts in your drawable layer-list is by creating a png file of the text and adding it using bitmap. Here is one example of it. <?xml version=”1.0″ encoding=”utf-8″?> <layer-list xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:drawable=”@drawable/background”/> <item android:bottom=”150dp”> <bitmap android:gravity=”center” android:src=”https://stackoverflow.com/questions/38161959/@drawable/logo”/> </item> <item android:top=”60dp”> <bitmap android:gravity=”center” android:tint=”@android:color/white” android:src=”@drawable/text”/> </item> </layer-list>
Using layer-list to display some drawable images
Update your layer-list as follows <?xml version=”1.0″ encoding=”utf-8″?> <layer-list xmlns:android=”http://schemas.android.com/apk/res/android”> <item> <shape> <gradient android:centerX=”0.5″ android:centerY=”0.1″ android:endColor=”#08e25b” android:gradientRadius=”300dp” android:startColor=”#b7e9c9″ android:type=”radial” /> </shape> </item> <item android:width=”48dp” android:height=”48dp” android:bottom=”68dp” android:right=”-20dp”> <bitmap android:gravity=”bottom|right” android:src=”@drawable/peas” /> </item> <item android:width=”68dp” android:height=”68dp” android:bottom=”-20dp” android:left=”-20dp”> <bitmap android:gravity=”bottom|left” android:src=”@drawable/peas” /> </item> </layer-list>
Understanding Android’s
The values for left, top, right and bottom are measured from their respective edge. So left=0dp, top=0dp, bottom=0dp & right=50dp will give you a rectangle that is (match_parent – 50dp) wide and not 50dp wide. Therefore larger values for “right” will actually give you a smaller rectangle. The same would apply to the other value, … Read more
setBackgroundResource() discards my XML layout attributes
I ran into this issue as well. Presumably you’re using a LayerList resource drawable? That’s what I was using. Unfortunately, I found no “real” way of fixing it, it seems like a bug in the code, but I didn’t chase it down. However, I was lucky in the sense that I was setting the “buggy” … Read more
How to center vector drawable in layer-list without scaling
I ran into the same problem trying to center vectors drawables on a layered list. I have a workaround, its not exactly the same but it works, you need to set a size for the entire drawable and add padding to the 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 … Read more
Style bottom Line in Android
It’s kind of a hack, but I think this is probably the best way to do it. The dashed line will always be on the bottom, regardless of the height. <layer-list xmlns:android=”http://schemas.android.com/apk/res/android”> <item> <shape android:shape=”rectangle” > <solid android:color=”#1bd4f6″ /> </shape> </item> <item android:top=”-2dp” android:right=”-2dp” android:left=”-2dp”> <shape> <solid android:color=”@android:color/transparent” /> <stroke android:dashGap=”10px” android:dashWidth=”10px” android:width=”1dp” android:color=”#ababb2″ /> … Read more