Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 如何创建平行四边形的形状背景?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试为我的textview制作平行四边形背景,但它没有正确显示…它显示以下输出
<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>

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

解决方法

作为@ mmlooloo的回答的替代方案,我建议使用xml-drawable解决方案(因为你还没有强调你正在寻找什么样的解决方案).在下面的示例中,我使用了一般视图,但您可以使用任何其他视图.

这是视图

<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://@R_607_10906@mas.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>

是这样的

大佬总结

以上是大佬教程为你收集整理的android – 如何创建平行四边形的形状背景?全部内容,希望文章能够帮你解决android – 如何创建平行四边形的形状背景?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。