如何在形状xml中的笔触两侧制作圆角

时间:2018-08-09 11:15:09

标签: android android-shape

我试图创建这样的形状:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
  <corners android:radius="0.5dp"></corners>
  <stroke
    android:width="@dimen/strokeWidth"
    android:color="@color/mycolor"/>
  <solid android:color="@color/transparent"></solid>
</shape>

这就是我得到的:

Round corner part

我可以将内角设为外边界(现在是正方形)吗?

3 个答案:

答案 0 :(得分:1)

尝试

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <stroke
                android:width="30dp"
                android:color="#000000" />
            <corners android:radius="40dp" />
        </shape>
    </item>
</layer-list>

输出:-

enter image description here

答案 1 :(得分:1)

您的代码进行了一些更改,输出准备就绪:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="30dp"></corners> <!-- change this -->
    <stroke
        android:width="20dp"
        android:color="@color/black"/>
</shape>

输出:

enter image description here

答案 2 :(得分:0)

尝试一下, abc.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="-10dp"
        android:left="-10dp"
        android:right="-10dp"
        android:top="-10dp">
        <shape android:shape="rectangle">
            <stroke
                android:width="10dp"
                android:color="#ffffff" />
            <corners android:radius="20dp" />
        </shape>
    </item>
</layer-list>

layout.xml

android:background="@drawable/abc"