我想为我的形状制作一个像这样的按钮
有没有办法用 xml 来做到这一点?
就像设置一些点一样,就我而言,我有 5..
你需要的是创建一个shape xml file
在你的项目中drawable-xxx
文件夹,然后使用此形状作为按钮的背景。
这是名为的形状文件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 http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList.
EDIT:
请记住,我对形状的宽度和高度使用了某些值。如果您更改这些,您可能需要更改top, bottom and right attributes
。因此,在这种情况下,请考虑在项目中使用不同的值values
目录。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)