1

我想创建一个形状,例如下图,但我想用 XML代码(可绘制)创建它,我不想9.patch图像创建它! 在此处输入图像描述

如何使用 xml 代码创建此形状?

4

1 回答 1

1

这是一个解决方法

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp">
    <solid android:color="#FFFFFF"/>
    <corners 
    android:bottomRightRadius="0dp"
    android:bottomLeftRadius="0dp"
    android:topLeftRadius="15dp"
    android:topRightRadius="15dp"/>
</shape>

调整拐角半径以使您的上半部分弯曲!

或重叠这个椭圆形以获得所需的输出

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <!--circle filling color-->
    <solid android:color="#ffffff" />
    <stroke
    <!--radious can define in here-->
    android:width="1dp"
    android:color="#ffffff" />
    <corners
    android:bottomLeftRadius="2dp"
    android:bottomRightRadius="2dp"
    android:topLeftRadius="2dp"
    android:topRightRadius="2dp" />
</shape>

但基本上,这不是正确的方法!使用另一种方式,使用 9 补丁

于 2016-07-20T11:57:18.673 回答