方形布局边框与圆形内边缘

jch*_*tof 9 android list border layer

我正在尝试创建一个布局边框,其边角为正方形,内侧为圆形.我已经知道我需要创建一个由两个形状组成的.xml可绘制定义:一个具有笔划宽度和角半径,另一个仅具有笔划宽度:

可绘制/

round_border.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="4dp" android:color="#FF000000" />
    <padding android:left="7dp" android:top="7dp"
            android:right="7dp" android:bottom="7dp" />
    <corners android:radius="4dp" />
    <solid android:color="#FFC0C0C0" />
</shape> 
Run Code Online (Sandbox Code Playgroud)

square_border.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="2dp" android:color="#FF000000" />
    <solid android:color="#FFC0C0C0" />
</shape> 
Run Code Online (Sandbox Code Playgroud)

这些中的每一个都作为边框独立工作,如下所示:

android:background="@drawable/round_border" 
Run Code Online (Sandbox Code Playgroud)

但当他们中的任何一个或两个被添加到项目列表可绘制时,如下所示:

composite_border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <layer-list>
        <item android:drawable="@drawable/round_border"/>
        <!-- <item android:drawable="@drawable/square_border"/> -->
    </layer-list>
</shape> 
Run Code Online (Sandbox Code Playgroud)

和:

android:background="@drawable/composite_border"
Run Code Online (Sandbox Code Playgroud)

布局的背景是完全黑色而不仅仅是黑色边框.

任何人都知道如何使图层列表适用于此任务?

Ama*_*mal 5

Shape Drawable Doc您可以看到形状不能包含图层列表,因此您应该像这样定义composite_border.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/square_border"/>
    <item android:drawable="@drawable/round_border"/>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

请注意,我按照图层列表的文档中的说明更改了图层列表中项目的顺序,
Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top
并且您希望它从外部进行平方


ben*_*qus 2

square_border.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="2dp" 
            android:color="#FF000000"
    />
    <solid android:color="#FFC0C0C0" />
</shape>
Run Code Online (Sandbox Code Playgroud)

复合边框.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <layer-list>
        <item android:drawable="@drawable/round_border"/>
        <!-- <item android:drawable="@drawable/square_border"/> -->
    </layer-list>
</shape>
Run Code Online (Sandbox Code Playgroud)

注意评论和引号!=]