zoukankan      html  css  js  c++  java
  • Stbdroid之ShapeDrawable

    Shape可以定义矩形、椭圆形、线条、圆形


    <?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="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>


    下面是一些例子,修改上面的属性的效果图:

    layout就是一个ImageView

    <ImageView
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:background="@drawable/shape_style" />

    下面是shape的配置文件内容

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
    
        <corners android:radius="0dp" >
        </corners>
    
        <stroke
            android:width="10dp"
            android:color="@android:color/holo_blue_light" >
        </stroke>
    
    </shape>

    效果如左边的图,当上面改成

    android:radius="50dp"

    现在看下gradient,shape的内容如下

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
    
        <gradient
            android:endColor="#ffffffff"
            android:startColor="@android:color/holo_blue_bright" >
        </gradient>
    
    </shape>

    效果图如下,

    ,

    修改如下:

        <gradient
            android:endColor="#ffffffff"
            android:startColor="#ffffffff"
            android:centerColor="@android:color/holo_blue_bright"
            android:angle="90" >
        </gradient>

    图如下



    下面看下padding,首先ImageView的内容:

    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_icon"
            android:background="@drawable/shape_style" />


    shape的内容:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
    
        <padding android:left="5dp"
            android:top="5dp"
            android:right="5dp"
            android:bottom="5dp"/>
    <solid
        android:color="@android:color/holo_blue_bright"></solid>
    </shape>



    最后,看size和stroke

    同样是ImageView:

    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/shape_style" />

    shape_style内容:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
    
        <size android:width="200dp"
            android:height="100dp"/>
        <stroke
            android:width="10dp"
            android:color="@android:color/holo_blue_bright" />
    
    </shape>


    在shape_style中加入android:dashWidth="5dp"和 android:dashGap="5dp",效果如下:

  • 相关阅读:
    document.documentElement与document.body clientHeight,scrollHeight,clientWidth,scrollWidth区别
    dedecms 系统基本参数 里面的值 原来不在文件写的而是在数据库里面
    Jquery使用控制Div动画显示、隐藏
    DEDE常用模板标签 List|列表标签
    document.body.clientHeight 和 document.documentElement.clientHeight的区别
    js获取宽高
    javascript arguments(转)
    PHP json_encode() 函数介绍
    全面阐述overflow:hidden属性
    JS数组去重
  • 原文地址:https://www.cnblogs.com/riasky/p/3429370.html
Copyright © 2011-2022 走看看