android程式碼繪製邊框、橢圓、實線、虛線
阿新 • • 發佈:2019-01-10
1、繪製邊框:在res/drawable下建立XML檔案,將其設定為背景即可:
程式碼:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="#55666666"
/>
<solid
android:color ="#ffffff"
/>
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp"
>
</padding>
</shape>
2、繪製橢圓:
程式碼:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 圓角 -->
<corners
android:bottomLeftRadius="6dp"
android:bottomRightRadius="6dp"
android:radius="10dp"
android:topLeftRadius="6dp"
android:topRightRadius="6dp" />
<!-- 描邊 -->
<solid
android:width="1dp"
android:color="@color/bg_Gray" />
</shape>
3、繪製實線:
程式碼:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:dashGap="0dp"
android:dashWidth="2dp"
android:width="1dp"
android:color="#D5D5D5" />
<size android:height="2dp" />
</shape>
4、繪製虛線:
程式碼:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:dashGap="2dp"
android:dashWidth="3dp"
android:width="1dp"
android:color="#D5D5D5" />
<size android:height="2dp" />
</shape>