1. 使用 shape 繪制線條
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line" > <!-- 顯示一條虛線,破折線的寬度為 dashWith,破折線之間的空隙的寬度為 dashGap,當 dashGap=0dp 時,為實線 --> <stroke android:dashGap="3dp" android:dashWidth="2dp" android:width="1dp" android:color="#777777" /> <!-- 虛線的高度 --> <size android:height="2dp" /> </shape>
2. 使用 shape 繪制圓形
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <!-- 填充顏色 --> <solid android:color="#F0F0F0" ></solid> <!--線的寬度,顏色灰色--> <stroke android:width="2dp" android:color="#777777"></stroke> <!-- 矩形的圓角半徑 --> <corners android:radius="5dp" /> </shape>
3. 使用 shape 繪制矩形
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!-- 填充顏色 --> <solid android:color="#F0F0F0" ></solid> <!-- 顯示一條實線,線的寬度為 width,顏色為 color --> <!-- <stroke android:width="2dp" android:color="#E3E0D5"></stroke> --> <!-- 顯示一條虛線,破折線的寬度為 dashWith,破折線之間的空隙的寬度為 dashGap,當 dashGap=0dp 時,為實線 --> <stroke android:dashGap="2dp" android:dashWidth="5dp" android:width="2dp" android:color="#777777" /> <!-- 虛線的高度 --> <size android:height="10dp" /> <!-- 矩形的圓角半徑 --> <corners android:radius="0dp" /> </shape>
4. 使用 shape 繪制半圓角矩形
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!-- topLeftRadius、topRightRadius 為半圓角矩形上半部分的圓角半徑,bottomLeftRadius、bottomRightRadius 為矩形下半部分的圓角半徑,值為0表示直角 --> <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" /> <gradient android:angle="270" android:endColor="#d3d3d3" android:startColor="#d3d3d3" /> <stroke android:width="0.5dp" android:color="#d9d9d9" /> </shape>