android之shape的说明

        ShapeDrawable经常会用到,以前都是现用现查,这里做一个简单说明,以备以后查询

        Shape一共有四种类型,属性基本上都可以通用

        1, 矩形

         

<?xml version="1.0" encoding="utf-8"?>

<!--
     矩形
-->

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!--
        四个角的角度
        radius            :   为四个角设置相同的角度,优先低,会被下方面的四个方法也取代
        topLeftRadius     :   左上角角度
        topRightRadius    :   右上角角度
        bottomLeftRadius  :   左下角角度
        bottomRightRadius :   右下角角度
    -->
    <corners
        android:radius ="4dp"
        android:topLeftRadius = "12dp"
        android:topRightRadius ="12dp"
        android:bottomLeftRadius = "12dp"
        android:bottomRightRadius = "12dp"/>

    <!--
        渐变填充,与下方的solid互斥
        angle             :   渐变的角度,其值必须为45度的倍数,0 表示从左到右,90表示从上到下
        centerX           :   渐变中心点的横坐标
        centerY           :   渐变中心点的纵坐标,渐变中心点,会影响渐变的效果
        startColor        :   渐变开始颜色
        centerColor       :   渐变中间颜色(可以不设置)
        endColor          :   渐变结束颜色
        gradientRadius    :   渐变半径,仅当下方的type为radial时有效
        type              :   渐变类别 linear(线性)  radial(圆)  sweep(发射)
        useLevel          :   一般为false,作为 StateListDrawable为true
    -->
    <gradient
        android:angle="45"
        android:centerX="20"
        android:centerY="20"
        android:startColor="#ff4433"
        android:centerColor="#ee44dd"
        android:endColor="#004433"
        android:gradientRadius="10"
        android:type="radial"
        android:useLevel="false" />


    <!--
        纯色填充,与上面方的渐变填充互斥

    <solid
        android:color="#ff4433"/>-->

    <!--
        描边
        width              :   描边的宽度,越大边越宽
        color              :   描边的颜色
        dashWidth          :   组成虚线的线段的宽  (可为空,为空画的是实线)
        dashGap            :   虚线线段之间的距离  (可为空,此值与上面的值有一个为0或为空,则为实线)
    -->
    <stroke
        android:width="2dp"
        android:color="#004433"
        android:dashWidth="2dp"
        android:dashGap="2dp"/>

    <!--
        它表示不是shape的空白,而是包含它的view的空白
    -->
    <padding
        android:top="10dp"
        android:left="10dp"
        android:right="10dp"
        android:bottom="10dp"/>

    <!--
        一般情况下不会设置
    -->
    <size
        android:width="30dp"
        android:height="20dp" />

</shape>
      2, 椭圆

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <!--
        渐变填充,与下方的solid互斥
        angle             :   渐变的角度,其值必须为45度的倍数,0 表示从左到右,90表示从上到下
        centerX           :   渐变中心点的横坐标
        centerY           :   渐变中心点的纵坐标,渐变中心点,会影响渐变的效果
        startColor        :   渐变开始颜色
        centerColor       :   渐变中间颜色(可以不设置)
        endColor          :   渐变结束颜色
        gradientRadius    :   渐变半径,仅当下方的type为radial时有效
        type              :   渐变类别 linear(线性)  radial(圆)  sweep(发射)
        useLevel          :   一般为false,作为 StateListDrawable为true
    -->
    <gradient
        android:angle="45"
        android:startColor="#ff4433"
        android:centerColor="#ee44dd"
        android:endColor="#004433"
        android:gradientRadius="100"
        android:type="linear"
        android:useLevel="false" />


    <!--
        纯色填充,与上面方的渐变填充互斥

    <solid
        android:color="#ff4433"/>-->

    <!--
        描边
        width              :   描边的宽度,越大边越宽
        color              :   描边的颜色
        dashWidth          :   组成虚线的线段的宽  (可为空,为空画的是实线)
        dashGap            :   虚线线段之间的距离  (可为空,此值与上面的值有一个为0或为空,则为实线)
    -->
    <stroke
        android:width="2dp"
        android:color="#004433"
        android:dashWidth="2dp"
        android:dashGap="2dp"/>

</shape>

     3,线

    

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    <!--
        渐变填充,与下方的solid互斥
        angle             :   渐变的角度,其值必须为45度的倍数,0 表示从左到右,90表示从上到下
        centerX           :   渐变中心点的横坐标
        centerY           :   渐变中心点的纵坐标,渐变中心点,会影响渐变的效果
        startColor        :   渐变开始颜色
        centerColor       :   渐变中间颜色(可以不设置)
        endColor          :   渐变结束颜色
        gradientRadius    :   渐变半径,仅当下方的type为radial时有效
        type              :   渐变类别 linear(线性)  radial(圆)  sweep(发射)
        useLevel          :   一般为false,作为 StateListDrawable为true
    -->
    <gradient
        android:angle="45"
        android:centerX="20"
        android:centerY="20"
        android:startColor="#ff4433"
        android:centerColor="#ee44dd"
        android:endColor="#004433"
        android:gradientRadius="10"
        android:type="radial"
        android:useLevel="false" />


    <!--
        纯色填充,与上面方的渐变填充互斥

    <solid
        android:color="#ff4433"/>-->

    <!--
        描边
        width              :   描边的宽度,越大边越宽
        color              :   描边的颜色
        dashWidth          :   组成虚线的线段的宽  (可为空,为空画的是实线)
        dashGap            :   虚线线段之间的距离  (可为空,此值与上面的值有一个为0或为空,则为实线)
    -->
    <stroke
        android:width="2dp"
        android:color="#004433"
        android:dashWidth="2dp"
        android:dashGap="2dp"/>
</shape>
       4,环形

     

<?xml version="1.0" encoding="utf-8"?>

<!--
    innerRadius   :   圆环的内半径
    thickness     :   环的宽度
    useLevel      :   必须设置成false,否则无法达到需要的效果
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring"
    android:innerRadius="80dp"
    android:thickness="10dp"
    android:useLevel="false">

    <!--
        渐变填充,与下方的solid互斥
        angle             :   渐变的角度,其值必须为45度的倍数,0 表示从左到右,90表示从上到下
        centerX           :   渐变中心点的横坐标
        centerY           :   渐变中心点的纵坐标,渐变中心点,会影响渐变的效果
        startColor        :   渐变开始颜色
        centerColor       :   渐变中间颜色(可以不设置)
        endColor          :   渐变结束颜色
        gradientRadius    :   渐变半径,仅当下方的type为radial时有效
        type              :   渐变类别 linear(线性)  radial(圆)  sweep(发射)
        useLevel          :   一般为false,作为 StateListDrawable为true
-->
    <gradient
        android:angle="45"
        android:centerX="20"
        android:centerY="20"
        android:startColor="#ff4433"
        android:centerColor="#ee44dd"
        android:endColor="#004433"
        android:gradientRadius="10"
        android:type="radial"
        android:useLevel="false" />


    <!--
        纯色填充,与上面方的渐变填充互斥

    <solid
        android:color="#ff4433"/>-->

    <!--
        描边
        width              :   描边的宽度,越大边越宽
        color              :   描边的颜色
        dashWidth          :   组成虚线的线段的宽  (可为空,为空画的是实线)
        dashGap            :   虚线线段之间的距离  (可为空,此值与上面的值有一个为0或为空,则为实线)
    -->
    <stroke
        android:width="2dp"
        android:color="#004433"
        android:dashWidth="2dp"
        android:dashGap="2dp"/>

</shape>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值