[英]Android XML layer-list: How to position the top layer
I have this XML drawable - tab_background_unselected: 我有这个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 shape: 创建这个形状:
and this arrow shape xml drawable - tab_selected_arrow: 这个箭头形状xml drawable - 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 shape: 创建这个形状:
I'm using this drawable XML (instead of PNG file) in order to create a layer-list: 我正在使用这个可绘制的XML(而不是PNG文件)来创建一个图层列表:
<?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 final image to look like this: 但我希望最终图像看起来像这样:
I don't know how to set the gravity of the arrow (the second item and the top layer) to center|bottom... I've tried using bitmap
tag but it only accepts image files. 我不知道如何将箭头的重力(第二项和顶层)设置为居中|我已经尝试使用
bitmap
标签,但它只接受图像文件。
I need this to be a XML drawable because 我需要这是一个XML drawable因为
Use an inner Bitmap
drawable inside the item
, and set gravity
for it: 在
item
使用内部Bitmap
drawable,并为其设置gravity
:
<item android:drawable="@drawable/tab_background_unselected">
</item>
<item>
<bitmap
android:gravity="bottom|center_horizontal"
android:src="@drawable/tab_selected_arrow" />
</item>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.