Android中UI设计之shape属性

在Android的UI设计时,难免会遇到使用控件如TextVeiw、Button等情况,如果要使它们更好看,就要使用到自定义background了,而shape就算常用的一种背景边框。

shape的基本属性有:

  1. corners 圆角
  2. solid 填充色
  3. stroke 描边(控件的边)
  4. gradient 渐变色
  5. padding 内边距(不常用)
  6. size 定义图形的大小(不常用)

shape本身属性有:

  1. rectangle 四边形
  2. oval 椭圆形
  3. line 线形
  4. ring 环形

shape的自身属性比较好理解,就算那四种形状;下面主要是理解它的6种基本属性。

1、corners

<corners
    android:radius="dimension" />//全部的圆角半径

如果控件四个角的角度不同,还需要分别设置

<corners
    android:topLeftRadius="dimension" //左上角的圆角半径
    android:topRightRadius="dimension"//右上角的圆角半径
    android:bottomLeftRadius="dimension" //右下角的圆角半径
    android:bottomRightRadius="dimension"//左下角的圆角半径
      />

注意:bottomLeftRadius为右下角的圆角半径,bottonRightRadius为左下角的圆角半径。

2、solid 内部填充色

它只有一个属性:

<sloid color="#ffffff"/>

3、stroke 描边属性 可以定义描边的宽度、颜色、虚实线等

<stroke
    android:width="dimension" //描边的宽度
    android:color="#FFFFFF" //描边的颜色
    //下面两个属性为 描边虚实线
    android:dashWidth="dimension" //虚线的宽度
    android:dashGap="dimension" //虚线的间隔
    />

4、gradient 定义渐变色,可以定义两色渐变和三色渐变以及渐变的样式

<gradient
    android:type=["linear|radial|sweep"] //共有三种渐变样式 线性渐变/放射渐变/扫描渐变
    android:angle="integer" //渐变角度,必须为45的倍数,0为从左到右,90为从上到下
    android:centerX="float" //渐变中心X的相对位置,范围为0~1
    android:centerY="float" //渐变中心Y的相对位置,范围为0~1
    android:startColor="color" //渐变开始点的颜色
    android:centerColor="color"  //渐变中间点的颜色,在开始与结束点之间
    android:endColor="color" //渐变结束点的颜色
    android:gradientRadius="float" //渐变的半径,只有当渐变样色为radial时,才有效
    android:useLevel=["true"|"false"] />//使用LevelListDrawable时就要设置为true;设置为false时才有渐变效果

5、size和padding

不常用,它们所具有的功能,控件本身也能实现

猜你喜欢

转载自blog.csdn.net/weixin_38664232/article/details/84642787