【问题标题】:How to design this shape in android如何在android中设计这个形状
【发布时间】:2018-10-02 09:32:37
【问题描述】:

我想制作这个形状,因为我尝试使用 layer-list 来设计这种形状,但它并没有完全按照我想要的方式发生。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item >
        <shape android:shape="rectangle">
            <solid android:color="@color/APP_PRIMARY"/>
            <corners android:topRightRadius="100dp"
                android:bottomRightRadius="100dp"/>
        </shape>
    </item>
    <item android:width="100dp" >
        <shape android:shape="rectangle">
            <solid android:color="@color/white"/>
            <corners android:topRightRadius="90dp"
                android:bottomRightRadius="90dp"/>
        </shape>
    </item>
</layer-list>

以上代码的输出是

所需的输出。

【问题讨论】:

  • 使用Path制作自定义视图。
  • 去自定义视图

标签: java android xml drawable android-drawable


【解决方案1】:

这正是你想要的

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
    <shape android:shape="rectangle">
        <solid android:color="@color/colorPrimary"/>
        <corners android:radius="90dp"
            />
    </shape>
</item>
<item android:width="100dp" >
    <shape android:shape="rectangle">
        <solid android:color="#ffff"/>
        <corners android:radius="90dp"/>
    </shape>
</item>
<item android:width="90dp" >
    <shape android:shape="rectangle">
        <solid android:color="@color/red"/>
        <corners android:radius="90dp"
            />
    </shape>
</item>

告诉我它是否有效。谢谢

【讨论】:

  • 它不工作。顺便说一句,您不能将android:width="100dp" 设置为低于 23 api。
【解决方案2】:

您可以使用由两个视图组成的水平线性布局 你可以使用这个drawable的正确视图

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The bottom layer is blue square.-->
<item
    android:left="5dp"
    android:top="5dp"
    android:right="5dp"
    android:bottom="5dp">
    <shape>
        <solid android:color="@color/accentYellowCanary" />
        <size android:height="100dp"
            android:width="200dp" />
        <corners android:topLeftRadius="50dp"
            android:bottomLeftRadius="50dp"
            android:topRightRadius="50dp"
            android:bottomRightRadius="50dp"/>
    </shape>
</item>

<!-- The middle layer is green circle.-->
<item
    android:left="5dp"
    android:top="5dp"
    android:right="150dp"
    android:bottom="5dp">
    <shape android:shape="oval">
        <size
            android:width="100dp"
            android:height="100dp" />
        <solid android:color="#FFF" />
    </shape>
</item>

这将导致:

你可以使用左边的

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The bottom layer is blue square.-->
<item
    android:left="5dp"
    android:top="5dp"
    android:right="5dp"
    android:bottom="5dp">
    <shape>
        <solid android:color= "@color/offWhite"/>
        <size android:height="100dp"
            android:width="200dp" />
        <corners android:topLeftRadius="50dp"
            android:bottomLeftRadius="50dp"
            android:topRightRadius="50dp"
            android:bottomRightRadius="50dp"/>
    </shape>
</item>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多