首先,在res下面新建一個文件夾drawable,在drawable下面新建三個xml文件:shape_corner_down.xml、shape_corner_up.xml和shape_corner.xml,分別是下面兩個角是圓角邊框,上面兩個角是圓角邊框,四個角所有是圓角邊框。android
shape_corner_down.xml:spa
1code 2xml 3utf-8 4ci 5get 6it 7io |
<?xml version= "1.0" encoding= "utf-8" ?> table <shape xmlns:android= "http://schemas.android.com/apk/res/android" > <solid android:color= "#0099CC" /> <corners android:bottomRightRadius= "20dp" android:bottomLeftRadius= "20dp" /> <stroke android:width= "1dp" android:color= "#000000" /> </shape> |
shape_corner_up.xml:
1 2 3 4 5 6 7 |
<?xml version= "1.0" encoding= "utf-8" ?> <shape xmlns:android= "http://schemas.android.com/apk/res/android" > <solid android:color= "#CCCC99" /> <corners android:topLeftRadius= "20dp" android:topRightRadius= "20dp" /> <stroke android:width= "1dp" android:color= "#000000" /> </shape> |
shape_corner.xml:
1 2 3 4 5 6 7 8 9 |
<?xml version= "1.0" encoding= "utf-8" ?> <shape xmlns:android= "http://schemas.android.com/apk/res/android" > <solid android:color= "#99CCFF" /> <corners android:topLeftRadius= "20dp" android:topRightRadius= "20dp" android:bottomRightRadius= "20dp" android:bottomLeftRadius= "20dp" /> <stroke android:width= "1dp" android:color= "#000000" /> </shape> |
<solid android:color>設置了背景顏色。android:topLeftRadius、android:topRightRadius、android:bottomLeftRadius、android:bottomRightRadius分別是左上角、右上角、左下角、右下角的半徑值,設置了半徑值,相應的角就是圓角,半徑值越大,圓角就越大。<stroke>設置邊界屬性,如邊界的寬度、顏色等。
在activity_main.xml上面放置三個LinearLayout,分別設置android:background屬性爲shape_corner_up.xml、shape_corner_down.xml和shape_corner.xml,運行結果以下:
![](http://static.javashuo.com/static/loading.gif)