Android的 - 使箭头形状与XML
答
你需要的是建立在项目的drawable-xxx
文件夹shape xml file
然后用这个形状背景的按钮。
这里是被称为形状文件arrow_shape.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Colored rectangle-->
<item>
<shape android:shape="rectangle">
<size
android:width="100dp"
android:height="40dp" />
<solid android:color="#5EB888" />
<corners android:radius="0dp"/>
</shape>
</item>
<!-- This rectangle for the top arrow edge -->
<!-- Its color should be the same as the layout's background -->
<item
android:top="-40dp"
android:bottom="65dp"
android:right="-30dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
<!-- This rectangle for the lower arrow edge -->
<!-- Its color should be the same as the layout's background -->
<item
android:top="65dp"
android:bottom="-40dp"
android:right="-30dp">
<rotate
android:fromDegrees="-45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
</layer-list>
然后把它作为按钮的背景,例如
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/arrow_shape"/>
下面是截图:
更多的信息Layer-List
你可以找到here。
编辑:
但请记住,我使用的某些值形状的宽度和高度。如果您更改了那些,则可能需要更改top, bottom and right attributes
的值。因此,在这种情况下,请考虑在您的项目的values
目录中使用不同的值。
如果背景是动态布局,则显示其白色通道[](http://i.stack。 imgur.com/FKtR1.png) – 2016-08-01 10:32:13