【问题标题】:Custom Shapes :Android自定义形状:Android
【发布时间】:2015-05-12 14:01:08
【问题描述】:

我想画这样的自定义形状-

我想用 xml 来做这个。我似乎无法理解 layer-list 和 items 的使用,因为它们的行为很奇怪。我应该如何绘制这样的形状?不要指望完整的代码,只要给我想法或指出正确的方向。 谢谢

编辑:这是我迄今为止尝试过的代码

<item>
    <shape android:shape="rectangle">
        <size
            android:width="100dp"
            android:height="40dp" />
        <solid android:color="#ff0000" />
    </shape>
</item>


<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>

【问题讨论】:

  • 我尝试使用层列表和里面的项目..但我从来没有得到我想要的形状
  • 请贴出你试过的代码。
  • 我已经对问题进行了编辑

标签: android xml drawable shape layer-list


【解决方案1】:

这里有点接近

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

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

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

    <!-- inner white rectangle -->
    <item
        android:bottom="60dp"
        android:right="30dp"
        android:left="100dp">
        <rotate
            android:fromDegrees="75">
            <shape android:shape="rectangle">
                <size
                    android:width="100dp"/>
                <solid android:color="#ffffff" />
            </shape>
        </rotate>
    </item>


</layer-list>

【讨论】:

  • 抱歉,我们实际上是 2 张图片……我对问题进行了编辑……我只想要绿色形状
  • 好的。我刚刚对代码进行了最后一次提交。现在完全符合您的要求。如果这对您有帮助,请投票并接受它:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-05-18
  • 2012-12-01
  • 2014-12-06
  • 2016-08-16
  • 2016-04-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多