一、前提
在这里会讲解shape属性的各个元素,以及效果展示及使用
二、目标
shape
三、内容
1、首先创建一个shape.xml文件以及在布局文件中添加一个按钮用来展示添加属性后的样式
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
</shape>
在shape中第一个可以添加的要素是android:shape=“”(可选可不选,可以直接在里面添加颜色形状什么的,直接用在控件上)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
</shape>
其中shape中有四个可选要素
android:shape="rectangle" 表示矩形
android:shape="line" 表示线形(一般不怎么用)
android:shape="oval" 表示椭圆
android:shape="ring" 表示圆环
2、就shape里面的元素开讲,拿矩形举例
(1)solid 用于指定内部的填充色,里面的属性只有color一条
<solid android:color="color"/>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#24e9d2"/>
</shape>
属性展示: 效果展示:
(2)corners用于指定圆角,里面的属性有5条
<corners android:radius=""/>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#24e9d2"/>
<corners android:radius="20dp"/>
</shape>
android:radius="20dp" |
所有圆角半径 | ![]() |
![]() |
android:topLeftRadius="20dp" | 左上圆角半径 | ![]() |
|
android:topRightRadius="20dp" | 右上圆角半径 |