Android開發之給控制元件設定圓角邊框
阿新 • • 發佈:2019-01-11
先上效果圖:
具體步驟:
1.在drawable資料夾下新建一個xml檔案。
2.在裡面填上以下內容:
3.在xml檔案中使用:<?xml version="1.0" encoding="utf-8"?> <!--自定義的控制元件圓角背景--> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/white"/> <padding android:top="10px" android:bottom="10px"/> <corners android:radius="50px"/> <stroke android:width="1px" android:color="#f08200"/> </shape>
4.註釋:
corners ----------圓角
gradient ----------漸變
padding ----------內容離邊界距離
size ------------大小
solid ----------填充顏色
stroke ----------描邊
注意的是corners的屬性bottomLeftRadius為右下角、bottomRightRadius為左下角
shape製作虛線
沒有dashGap屬性則為實線
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line" > <stroke android:dashGap="3dp" android:dashWidth="8dp" android:width="1dp" android:color="#63a219" /> <size android:height="1dp" /> </shape>
4.0以上虛線變實線在xml檔案中增加:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/xuxian"
android:layerType="software" />
shape製作漸變
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:angle="270.0" android:endColor="#ffffff" android:startColor="#000000" /> </shape>
參考:http://www.cnblogs.com/tinyphp/p/3829895.html