Android 带有圆形内边缘的方形布局边框
我正在尝试创建一个布局边界,其角在外部为方形,内部为圆形。我发现我需要创建一个由两个形状组成的.xml可绘制定义:一个具有笔划宽度和角半径,另一个仅具有笔划宽度: 可抽出式装置 round_border.xmlAndroid 带有圆形内边缘的方形布局边框,android,list,border,layer,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" />
<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>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp" android:color="#FF000000" />
<solid android:color="#FFC0C0C0" />
</shape>
<?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>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp"
android:color="#FF000000"
/>
<solid android:color="#FFC0C0C0" />
</shape>
<?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>
但当它们中的一个或两个都添加到可绘制的项目列表时,如下所示:
composite_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>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp" android:color="#FF000000" />
<solid android:color="#FFC0C0C0" />
</shape>
<?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>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp"
android:color="#FF000000"
/>
<solid android:color="#FFC0C0C0" />
</shape>
<?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>
布局的背景是完全黑色的,而不仅仅是黑色的边框
有人知道如何使图层列表用于此任务吗?square\u 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>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp" android:color="#FF000000" />
<solid android:color="#FFC0C0C0" />
</shape>
<?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>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp"
android:color="#FF000000"
/>
<solid android:color="#FFC0C0C0" />
</shape>
<?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>
composite_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>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp" android:color="#FF000000" />
<solid android:color="#FFC0C0C0" />
</shape>
<?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>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp"
android:color="#FF000000"
/>
<solid android:color="#FFC0C0C0" />
</shape>
<?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>
注意注释和引号!=] 从中可以看出,形状中不能包含图层列表,因此您应该像这样定义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>
请注意,我更改了图层列表中项目的顺序,如图层列表文档中所述列表中的每个可绘制项都是按照列表的顺序绘制的,列表中最后一个可绘制项绘制在顶部
并且您希望它从外部被平方尝试一下这个方法就足够了:
<LinearLayout
android:id="@+id/layout_wellbeing"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:background="@drawable/rounded_corner_leuvan"
android:orientation="horizontal" >
</LinearLayout>
纯色
为背景色
<LinearLayout
android:id="@+id/layout_wellbeing"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:background="@drawable/rounded_corner_leuvan"
android:orientation="horizontal" >
</LinearLayout>
笔划
为边框
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="@color/white"/>
<stroke android:width="1dp" android:color="#ffaaaaaa" />
<size
android:width="15dp"
android:height="15dp"/>
</shape>
创建一个类似round_background.xml的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#CCCC33"/>
<size
android:width="35dp"
android:height="35dp"/>
</shape>
在设置为背景的版面中
<LinearLayout
android:id="@+id/layout_wellbeing"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:background="@drawable/rounded_corner_leuvan"
android:orientation="horizontal" >
</LinearLayout>
谢谢-仍在寻找答案。谢谢分享!如果我想要一个边框和实体呢?