美文网首页
android Shape图形

android Shape图形

作者: yunhen | 来源:发表于2018-07-06 17:56 被阅读11次
    <?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>
    

    android:shape=["rectangle" | "oval" | "line" | "ring"]
    矩形(rectangle)、椭圆(oval)、线(line)、圆环(ring)。

    shape的形状,默认为矩形,可以设置为矩形(rectangle)、椭圆形(oval)、线性形状(line)、环形(ring)
    下面的属性只有在android:shape="ring"时可用:
    android:innerRadius 尺寸,内环的半径。
    android:innerRadiusRatio 浮点型,以环的宽度比率来表示内环的半径,
    android:thickness 尺寸,环的厚度
    android:thicknessRatio 浮点型,以环的宽度比率来表示环的厚度,例如,如果android:thicknessRatio="2",
    android:useLevel boolean值,如果当做是LevelListDrawable使用时值为true,否则为false.

    solid标签:填充颜色
    corners标签:圆弧
    gradient标签:渐变
    stroke标签:边框
    size标签:图像的大小,比如设置啦边框,那这个属性只的就是这个边框的大小

    solid 内容

    android:color="color" 填充颜色

    corners 圆角大小

    android:radius="dimension" //全部的圆角半径
    android:topLeftRadius="dimension" //左上角的圆角半径
    android:topRightRadius="dimension" //右上角的圆角半径
    android:bottomLeftRadius="dimension" //左下角的圆角半径
    android:bottomRightRadius="dimension" //右下角的圆角半径

    gradient 渐变

    android:type=["linear" | "radial" | "sweep"] //共有3中渐变类型,线性渐变(默认)/放射渐变/扫描式渐变
    android:angle="integer" //渐变角度,必须为45的倍数,0为从左到右,90为从上到下
    android:centerX="float" //渐变中心X的相当位置,范围为0~1
    android:centerY="float" //渐变中心Y的相当位置,范围为0~1
    android:startColor="color" //渐变开始点的颜色
    android:centerColor="color" //渐变中间点的颜色,在开始与结束点之间
    android:endColor="color" //渐变结束点的颜色
    android:gradientRadius="float" //渐变的半径,只有当渐变类型为radial时才能使用
    android:useLevel=["true" | "false"] //使用LevelListDrawable时就要设置为true。设为false时才有渐变效果

    android:type:渐变类型
    linear 线性渐变,默认的渐变类型
    radial 放射渐变,设置该项时,android:gradientRadius也必须设置
    sweep 扫描性渐变

    stroke 这是描边属性,可以定义描边的宽度,颜色,虚实线等

    android:width="dimension" //描边的宽度
    android:color="color" //描边的颜色
    // 以下两个属性设置虚线
    android:dashWidth="dimension" //虚线的宽度,值为0时是实线
    android:dashGap="dimension" //虚线的间隔

    size和padding

    这两个基本上不怎么用,因为他们所具有的功能,控件本身也能实现。 size:是用来定义图形的大小的。

    小栗子:

    画个竖线

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle"
        android:useLevel="true">
        <size
            android:width="1dp"
            android:height="5dp" />
        <solid android:color="@color/YunBlue"/>
    </shape>
    

    画个左面有圆角 右面没有的图形

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle"
        android:useLevel="true">
        <stroke
            android:width="2px"
            android:color="@color/YunBlue" />
        <solid android:color="@color/YunBlue"/>
        <!-- 圆角半径是高度的一般就是一个圆弧了 -->
        <corners
            android:bottomLeftRadius="5dp"
            android:topLeftRadius="5dp" />
    </shape>
    

    相关文章

      网友评论

          本文标题:android Shape图形

          本文链接:https://www.haomeiwen.com/subject/myubuftx.html