實現原理使用layer-list對shape進行疊加顯示。javascript
直接上代碼:java
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <corners android:radius="10dp" /> <solid android:color="@color/purple" /> </shape> </item> <item android:top="10dp"> <shape> <solid android:color="@color/purple" /> </shape> </item> </layer-list>
以上是半圓的實現效果。android
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <stroke android:width="1dp" android:color="@color/purple" /> <solid android:color="@color/white" /> </shape> </item> <item android:left="1dp" android:right="1dp"> <shape> <solid android:color="@color/white" /> </shape> </item> </layer-list>
半邊框的實現效果。3d
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <corners android:radius="5dp" /> <solid android:color="@color/white" /> <stroke android:width="1dp" android:color="@color/purple" /> </shape> </item> <item android:bottom="5dp"> <shape> <solid android:color="@color/white" /> <stroke android:width="1dp" android:color="@color/purple" /> </shape> </item> <item android:bottom="5dp" android:left="1dp" android:right="1dp"> <shape> <solid android:color="@color/white" /> </shape> </item> </layer-list>
奉上一個半圓而且半邊框的shape,但願能給你們帶來幫助。code