在res/drawable下的XML文件有Shape这样的一个属性,这个属性的主要作用是对一些UI进行美化、设置指定形状等
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:shape="oval"
android:shape="line"
android:shape="ring">
</shape>
第一种为矩形,第二种为椭圆,第三种为线形,第四种为环形。开发中使用矩形和椭圆较多。
在解释属性的意思之前,先把layout中的布局贴出来
<Button
android:layout_width="100dp"
android:layout_height="40dp"
android:text="你好呀"
android:background="@drawable/myshape"/> //这里就是引用shape属性文件
接下来说说其里面的属性
(1)solid 实心
<solid android:color="#FF0000" /> //为UI内部填充颜色
<corners
android:radius="15dp" //把所有圆角的半径设为15dp,而下面是分别设四个角
android:topLeftRadius="5dp"
android:topRightRadius="8dp"
android:bottomLeftRadius="6dp"
android:bottomRightRadius="10dp"/>
(3)gradient 渐变
<gradient
android:startColor="#000000"
android:endColor="#FFFFFF"
android:angle="180" //渐变角度
android:type="linear"/>
type:linear是线性渐变,从左到右或从上到下;
sweep径向渐变,是圆心到圆边;
radial是角度渐变,按照角度来变换颜色。
(4)stroke 描边
<stroke
android:color="#000000"
android:dashWidth="3dp" //“-”的宽度
android:width="2dp" //线的宽度
android:dashGap="3dp"/> //间隔
(5)padding 间距
(6)size 大小
下面这两个属性在Layout的XML文件中经常配置,这里不解释了。