我正在尝试为我的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://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>
它是这样的: