虚线
属性 | 属性值 | 作用 |
---|---|---|
shape | line | 设置形状为线型 |
stroke | 以下属性 | |
width | integer | 线的厚度 |
color | color | 线的颜色 |
dashGap | integer | 每段线的间隔(为0的话就是直线) |
dashWidth | integer | 每段线的长度 |
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<!--android:width虚线的高度-->
<!--android:width的值必须要小于用它做背景的View的height-->
<stroke
android:width="1dp"
android:color="#f00"
android:dashGap="2sp"
android:dashWidth="10dp" />
</shape>
椭圆边框
属性 | 属性值 | 描述 |
---|---|---|
shape | oval | 椭圆 |
stroke | 设置边框属性 | |
corners | 角度 | 设置四个角的角度 |
代码如下:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="2dp"
android:color="#49da2b"
android:dashGap="20sp"
android:dashWidth="18dp" />
<corners android:radius="10dp"/>
</shape>
环 ring
属性 | 属性值 | 描述 |
---|---|---|
shape | ring | 环 |
innerRadiusRatio | float | 环内径比(屏幕宽度/半径) |
thicknessRatio | float | 厚度比(屏幕宽度/厚度) |
type | sweep | 渐变 |
代码如下:
<?xml version="1.0" encoding="utf-8"?><!--android:useLevel该值设为false,否则会看不到圆环画面-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="4"
android:shape="ring"
android:thicknessRatio="4"
android:useLevel="false">
<gradient
android:endColor="#cbd5e1"
android:startColor="#5adece"
android:type="sweep" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="1.0px"
android:insetRight="1.0px">
<selector>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="#154d91"
android:startColor="#24b124" />
<corners android:radius="10dp" />
<stroke
android:width="5dp"
android:color="#0f0" />
</shape>
</item>
</selector>
</inset>