Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android形状-方形,带圆形和不同的顶部颜色_Android_Xml Drawable_Shapedrawable - Fatal编程技术网

Android形状-方形,带圆形和不同的顶部颜色

Android形状-方形,带圆形和不同的顶部颜色,android,xml-drawable,shapedrawable,Android,Xml Drawable,Shapedrawable,我正在尝试创建一个可绘制的形状,如下所示 其中只有左上部分的颜色不同(此处为白色)。我以为放置一个较小尺寸的矩形可以让我实现这一点,但我错了。我走的方向对吗 这是我的drawable.xml文件 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape a

我正在尝试创建一个可绘制的形状,如下所示

其中只有左上部分的颜色不同(此处为白色)。我以为放置一个较小尺寸的矩形可以让我实现这一点,但我错了。我走的方向对吗

这是我的drawable.xml文件

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <size android:width="15dp" android:height="15dp"/>
        <solid android:color="@android:color/white" />
    </shape>
</item>
<item>
    <shape android:shape="oval">
        <solid android:color="@android:color/black" />
    </shape>
</item>
</layer-list>



创建一个自定义的
形状
类,并将其传递给
形状可移动的
构造函数哇!那是快速而完美的。非常感谢。如果我的尺码不一样,这意味着它不适合我?这里的逻辑是什么,比如60dp,40dp,30dp,10dp?那么你必须通过编程来创建它。你能告诉我如何减小圆的大小吗?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <size android:width="60dp" android:height="60dp"/>
            <solid android:color="@android:color/white" />
        </shape>
    </item>



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

    <item android:top="30dp" android:bottom="0dip">
        <shape android:shape="rectangle">
            <size android:width="10dp" android:height="10dp"/>
            <solid android:color="#ff0000" />
        </shape>
    </item>

    <item>
    <shape android:shape="oval">
        <stroke android:color="@android:color/black" android:width="1dp"/>
        <size android:width="60dp" android:height="60dp"/>
        <solid android:color="#ff0000" />
    </shape>
</item>

</layer-list>