gpt4 book ai didi

Android - 使用 xml 制作箭头形状

转载 作者:可可西里 更新时间:2023-11-01 18:55:07 24 4
gpt4 key购买 nike

我想为我的形状做一个像这样的按钮

enter image description here

有没有办法用 xml 做到这一点?就像设置一些点,在我的例子中我有 5..

最佳答案

您需要在项目的 drawable-xxx 文件夹中创建一个 shape xml 文件,然后使用此形状作为按钮的背景。

这是名为 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"/>

截图如下:

enter image description here

有关 Layer-List 的更多信息,您可以找到 here .

编辑:

请记住,我为形状的宽度和高度使用了某些值。如果您更改这些,您可能需要更改 top、bottom 和 right 属性 的值。因此,在这种情况下,请考虑在项目的 values 目录中使用不同的值。

关于Android - 使用 xml 制作箭头形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26143905/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com