Android中的Shape使用方法汇总

Shape在Android当中主要用来定义各种的形状属性的,在UI开发当中用的比较多。下面就来介绍一下各种属性的具体含义。
它的创建和引用方法跟状态选择器(selector)是一样的,需要先创建一个xml文件再引用。
文件位置:res/drawable/filename.xml
引用方法:
在代码中: R.drawable.filename
在XML文件: @[package:]drawable/filename
一个官方示例:
<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape=["rectangle" | "oval" | "line" | "ring"] >
    <corners
        android:radius="integer"
        android:topLeftRadius="integer"
        android:topRightRadius="integer"
        android:bottomLeftRadius="integer"
        android:bottomRightRadius="integer" />
    <gradient
        android:angle="integer"
        android:centerX="float"
        android:centerY="float"
        android:centerColor="integer"
        android:endColor="color"
        android:gradientRadius="integer"
        android:startColor="color"
        android:type=["linear" | "radial" | "sweep"]
        android:useLevel=["true" | "false"] />
    <padding
        android:left="integer"
        android:top="integer"
        android:right="integer"
        android:bottom="integer" />
    <size
        android:width="integer"
        android:height="integer" />
    <solid
        android:color="color" />
    <stroke
        android:width="integer"
        android:color="color"
        android:dashWidth="integer"
        android:dashGap="integer" />
</shape>

开头属性的含义
–android:shape 设置形状,分别有四个属性
–rectangle 矩形
–oval 圆形
–line 线型
–ring 环形
标签属性的含义
–corners 圆角
android:radius=”10dp” 四个角的半径
        android:topLeftRadius=”10dp” 左上角半径
        android:topRightRadius=”10dp” 右上角半径
        android:bottomLeftRadius=”10dp” 左下角半径
        android:bottomRightRadius=”10dp” 右下角半径
–gradient 渐变效果
 android:angle=”integer” 渐变角度,必须为45的整数倍
        android:centerX=”float” 渐变中心X的相当位置,范围为0~1
        android:centerY=”float” 渐变中心Y的相当位置,范围为0~1
        android:centerColor=”integer” 渐变中间的颜色
        android:endColor=”color” 渐变结束的颜色
        android:gradientRadius=”integer” 在设置径向渐变的时候需要此半径
        android:startColor=”color” 开始渐变的颜色
        android:type=[“linear” | “radial” | “sweep”] 渐变模式(linear线性、radial径向渐变、sweep扇形渐变)
        android:useLevel=[“true” | “false”] 使用LevelListDrawable时就要设置为true。设为false时才有渐变效果
–padding 间隔(设置上下左右四个方向的间隔)
android:left=”integer”
android:top=”integer”
android:right=”integer”
android:bottom=”integer”
<!– 设置各个方向的间隔 –>
–size 形状的大小
        android:width=”integer”
        android:height=”integer”
–solid 充填纯色
        android:color=”color”
–stroke 描边效果
        android:width=”integer” 边宽
        android:color=”color” 边色
        android:dashWidth=”integer” 虚线短横线宽度
        android:dashGap=”integer” 虚线短横线间隔
星星小路,版权所有丨转载请注明转自: http://xxxlu.top/archives/202
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值