gpt4 book ai didi

android - 如何创建平行四边形形状的背景?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:24:11 28 4
gpt4 key购买 nike

我正在尝试为我的 TextView 制作平行四边形背景,但它显示不正确......它显示在输出之后

enter image description here

<layer-list  >
<item>
<rotate
android:fromDegrees="10"
android:toDegrees="10"
android:pivotX="-40%"
android:pivotY="87%" >
<shape
android:shape="rectangle" >
<stroke android:color="#000000" android:width="10dp"/>

</shape>

</rotate>

</item>
</layer-list>

我需要这样的输出.........

enter image description here

最佳答案

作为@mmlooloo 的答案的替代方案,我建议使用 xml-drawable 解决方案(因为您没有确切强调您正在寻找哪种解决方案)。在下面的示例中,我使用了一个通用的 View,但是您可以使用任何其他 View 。

这是 View

<View
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:background="@drawable/shape" />

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="#13a89e" />
</shape>
</item>

<!-- This rectangle for the left side -->
<!-- Its color should be the same as layout's background -->
<item
android:right="100dp"
android:left="-100dp"
android:top="-100dp"
android:bottom="-100dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>

<!-- This rectangle for the right side -->
<!-- Their color should be the same as layout's background -->
<item
android:right="-100dp"
android:left="100dp"
android:top="-100dp"
android:bottom="-100dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>

</layer-list>

这是它的样子:

enter image description here

关于android - 如何创建平行四边形形状的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29094070/

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