6.2 Android Framework - ShapeDrawable

<?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="integer"
        android:centerY="integer"
        android:centerColor="integer"
        android:endColor="integer"
        android:startColor="integer"
        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
    • 表示图形的形状, ring和line必须搭配stroke使用, 针对ring的几个属性
    • android:innerRadius 圆环内半径
    • android:thickness 圆环厚度
    • android:innerRadiusRatio 内半径占整个Drawable宽度的比例
    • android:thicknessRatio 厚度占Drawable宽度的比例
    • android:useLevel 一般用false, 除非在LevelListDrawable中
  • corners
    • android:radius 为四个角的角度, 优先级低
    • android:topLeftRadius 左上角角度
    • android:topRightRadius 右上角角度
    • android:bottomLeftRadius 左下角角度
    • android:bottomRightRadius 右下角角度
  • gradient
    • 与solid互斥, 表示渐变效果
    • android:angle 渐变角度, 默认为0, 必须为45的整数倍, 0表示从左到右, 90表示从上到下
    • android:centerX 渐变中心点横坐标
    • android:centerY 渐变中心点纵坐标
    • android:startColor 渐变起始色
    • android:centerColor 渐变中间色
    • android:endColor 渐变结束色
    • android:gradientRadius 渐变半径, 当type为radial时有效
    • android:useLevel 一般为false作为StateListDrawable时为true
    • android:type 渐变类别
  • solid
    • 纯色填充, 通过android:color指定填充色
  • stroke
    • android:width 描边的宽度
    • android:color 描边的颜色
    • android:dashWidth 组成虚线的线段的宽度
    • android:dashGap 组成虚线的线段的间隔
  • padding
    • 表示包含shape的View的空白
    • android:left
    • android:top
    • android:right
    • android:bottom
  • size
    • 表示shape的固有大小 设置后getIntrinsicWidthgetIntrinsicHeight就不是默认的-1了
    • android:width
    • android:height
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值