<...">

Android XML layer list: how to place the top layer

I have this XML drawable - tab_background_unselected:

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > <solid android:color="@color/background_grey" /> </shape> </item> </layer-list> 

which creates this form:

background rectangle

and this xml drawable arrow is tab_selected_arrow:

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <rotate android:fromDegrees="45" android:pivotX="-40%" android:pivotY="87%" android:toDegrees="45" > <shape android:shape="rectangle" > <solid android:color="@color/background_dark_green" /> </shape> </rotate> </item> </layer-list> 

which creates this form:

top layer triangle

I use this drawable XML (instead of a PNG file) to create a list of layers:

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/tab_background_unselected"> </item> <item android:drawable="@drawable/tab_selected_arrow"> </item> </layer-list> 

but I want the last image to look like this:

final image

I do not know how to set the gravity of the arrow (second element and top layer) in the center | below ... I tried using the bitmap tag, but it only accepts image files.

I need this to be XML images because

  • I need it to be inside the selected selector
  • I do not want to create PNG and create different files for each screen resolution.
+7
android xml layer-list
source share
1 answer

Use the internal Bitmap , which can be extracted inside the item , and set gravity for it:

 <item android:drawable="@drawable/tab_background_unselected"> </item> <item> <bitmap android:gravity="bottom|center_horizontal" android:src="@drawable/tab_selected_arrow" /> </item> 
+9
source share

All Articles