代码之家  ›  专栏  ›  技术社区  ›  Kingfisher Phuoc

如何在shape xml中实现笔划两边的圆角

  •  2
  • Kingfisher Phuoc  · 技术社区  · 6 年前

    我试着创造一个这样的形状:

    <?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 回复  |  直到 6 年前
        1
  •  1
  •   halfer    6 年前

    代码和输出中的某些更改已就绪:

    <?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
  •  1
  •   Manohar    6 年前

    试试这个

    <?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

        3
  •  0
  •   Gautam Surani    6 年前

    试试这个, 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>
    

    布局.xml

    android:background="@drawable/abc"
    
    推荐文章