作为背景给定时ShapeDrawable无法正确绘制

时间:2018-08-16 19:47:02

标签: android drawable shapes

我当前的视图如下:

My current view with 'MyHouses'

我尝试使用以下代码绘制可绘制形状:

    <?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- Outer green rectangle-->
    <item
        android:bottom="140dp">
        <shape android:shape="rectangle">
            <size
                android:width="100dp"
                android:height="200dp" />
            <solid android:color="#ff5500" />
        </shape>
    </item>

    <item
        android:top="180dp"
        android:bottom="140dp">
        <shape android:shape="rectangle">
            <size
                android:width="20dp"/>
            <solid android:color="#ffffff" />
        </shape>
    </item>


    <!-- inner white rectangle -->
    <item
        android:bottom="-10dp"
        android:right="90dp"
        android:left="90dp">
        <rotate
            android:fromDegrees="-85">
            <shape android:shape="rectangle">
                <size
                    android:width="30dp"/>
                <solid android:color="#ffffff" />
            </shape>
        </rotate>
    </item>
</layer-list>

我设法得到了这种形状:

Shape using ShapeDrawable] 2

问题在于,当我将此形状作为布局的背景时,它看起来像这样:

enter image description here

我的最终目标是使它看起来像这样:

enter image description here

1 个答案:

答案 0 :(得分:0)

像这样更改您的可绘制文件

 <?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Outer green rectangle-->

    <item>
        <shape android:shape="rectangle">
            <solid android:color="#ff5500" />
        </shape>
    </item>

    <item android:bottom="-720dp">
        <rotate android:fromDegrees="-85">
            <shape android:shape="rectangle">
                <solid android:color="#ffffff" />
            </shape>
        </rotate>
    </item>


    <!-- inner white rectangle -->

</layer-list>