android之shape的说明

来源:互联网 发布:龙卷风网络收音机 mac 编辑:程序博客网 时间:2024/06/06 02:29

        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
原创粉丝点击