android shape

    xiaoxiao2021-12-14  22

    shape用于设定形状,可以在selector,layout等里面使用,有6个子标签,各属性如下:

    android:shape:设置样式rectangle,oval,line,ring。,默认rectangle

    <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 圆角 --> <corners android:radius="9dp" android:topLeftRadius="2dp" android:topRightRadius="2dp" android:bottomLeftRadius="2dp" android:bottomRightRadius="2dp"/><!-- 设置圆角半径 --> <!-- 渐变 --> <gradient android:startColor="@android:color/white" android:centerColor="@android:color/black" android:endColor="@android:color/black" android:useLevel="true" android:angle="45" android:type="radial" android:centerX="0" android:centerY="0" android:gradientRadius="90"/> <!-- 间隔 --> <padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp"/><!-- 各方向的间隔 --> <!-- 大小 --> <size android:width="50dp" android:height="50dp"/><!-- 宽度和高度 --> <!-- 填充 --> <solid android:color="@android:color/white"/><!-- 填充的颜色 --> <!-- 描边 --> <stroke android:width="2dp" android:color="@android:color/black" android:dashWidth="1dp" android:dashGap="2dp"/> </shape>

    solid:填充 android:color指定填充的颜色

    gradient:渐变 android:startColor和android:endColor分别为起始和结束颜色,

    android:angle是渐变角度,必须为45的整数倍 另外渐变默认的模式为android:type="linear",即线性渐变,

    可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径android:gradientRadius="50"。

    angle值对应的位置如图:

    stroke:描边

    dashWidth和dashGap属性,只要其中一个设置为0dp,则边框为实现边框

    android:width="20dp"                               设置边边的宽度 

    android:color="@android:color/black"  设置边边的颜色  android:dashWidth="2dp"                         设置虚线的宽度  android:dashGap="20dp"                          设置虚线的间隔宽度

    corners:圆角当且仅当控件类型位rectangle时才有作用,圆角半径的大小必须大于1 android:radius为角的弧度,值越大角越圆。 我们还可以把四个角设定成不同的角度,

    不需要设置不同圆角就android:Radius="20dp"   

    要设置不同圆角得,同时设置五个属性,则Radius属性无效

    android:Radius="20dp"                           设置四个角的半径

    android:topLeftRadius="20dp"              设置左上角的半径  android:topRightRadius="20dp"           设置右上角的半径  android:bottomLeftRadius="20dp"      设置右下角的半径  android:bottomRightRadius="20dp"    设置左下角的半径

    padding:间隔 可以设置上下左右四个方向的间隔
    转载请注明原文地址: https://ju.6miu.com/read-965011.html

    最新回复(0)