zoukankan      html  css  js  c++  java
  • Android Shape详解

    1. <shape>  
    2.     <!-- 实心 -->  
    3.     <solid android:color="#ff9d77"/>  
    4.     <!-- 渐变 -->  
    5.     <gradient  
    6.         android:startColor="#ff8c00"  
    7.         android:endColor="#FFFFFF"  
    8.         android:angle="270" />  
    9.     <!-- 描边 -->  
    10.     <stroke  
    11.         android:width="2dp"  
    12.         android:color="#dcdcdc" />  
    13.     <!-- 圆角 -->  
    14.     <corners  
    15.         android:radius="2dp" />  
    16.     <padding  
    17.         android:left="10dp"  
    18.         android:top="10dp"  
    19.         android:right="10dp"  
    20.         android:bottom="10dp" />  
    21. </shape>  

     

    solid:实心,就是填充的意思
    android:color
    指定填充的颜色

    gradient
    :渐变
    android:startColor
    android:endColor分别为起始和结束颜色,ndroid:angle是渐变角度,必须为45的整数倍。
    另外渐变默认的模式为android:type="linear",即线性渐变,可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径android:gradientRadius="50"

    stroke
    :描边
    android:width="2dp"
    描边的宽度,android:color 描边的颜色。
    我们还可以把描边弄成虚线的形式,设置方式为:
    android:dashWidth="5dp"

    android:dashGap="3dp"
    其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离。

    corners
    :圆角
    android:radius
    为角的弧度,值越大角越圆。

     

    demo:

    button_selector.xml:

    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <selector  
    3.     xmlns:android="http://schemas.android.com/apk/res/android">  
    4.     <item android:state_pressed="true" >  
    5.         <shape>  
    6.             <!-- 渐变 -->  
    7.             <gradient  
    8.                 android:startColor="#ff8c00"  
    9.                 android:endColor="#FFFFFF"  
    10.                 android:type="radial"  
    11.                 android:gradientRadius="50" />  
    12.             <!-- 描边 -->  
    13.             <stroke  
    14.                 android:width="2dp"  
    15.                 android:color="#dcdcdc"  
    16.                 android:dashWidth="5dp"  
    17.                 android:dashGap="3dp" />  
    18.             <!-- 圆角 -->  
    19.             <corners  
    20.                 android:radius="2dp" />  
    21.             <padding  
    22.                 android:left="10dp"  
    23.                 android:top="10dp"  
    24.                 android:right="10dp"  
    25.                 android:bottom="10dp" />  
    26.         </shape>  
    27.     </item>  
    28.     <item android:state_focused="true" >  
    29.         <shape>  
    30.             <gradient  
    31.                 android:startColor="#ffc2b7"  
    32.                 android:endColor="#ffc2b7"  
    33.                 android:angle="270" />  
    34.             <stroke  
    35.                 android:width="2dp"  
    36.                 android:color="#dcdcdc" />  
    37.             <corners  
    38.                 android:radius="2dp" />  
    39.             <padding  
    40.                 android:left="10dp"  
    41.                 android:top="10dp"  
    42.                 android:right="10dp"  
    43.                 android:bottom="10dp" />  
    44.         </shape>  
    45.     </item>  
    46.     <item>        
    47.         <shape>  
    48.             <solid android:color="#ff9d77"/>  
    49.             <stroke  
    50.                 android:width="2dp"  
    51.                 android:color="#fad3cf" />  
    52.             <corners  
    53.                 android:topRightRadius="5dp"  
    54.                 android:bottomLeftRadius="5dp"  
    55.                 android:topLeftRadius="0dp"  
    56.                 android:bottomRightRadius="0dp"  
    57.             />  
    58.             <padding  
    59.                 android:left="10dp"  
    60.                 android:top="10dp"  
    61.                 android:right="10dp"  
    62.                 android:bottom="10dp" />  
    63.         </shape>  
    64.     </item>  
    65. </selector>  

     

  • 相关阅读:
    linux shell 中"2>&1"含义-完美理解-费元星
    浅谈移动端设备标识码:DeviceID、IMEI、IDFA、UDID和UUID -费元星
    费元星-关于百度在数据仓库-层级架构上的思考
    费元星的第二代车,基于图像识别和超声波的无人智能小车
    【完美解决】Spark-SQL、Hive多 Metastore、多后端、多库
    【费元星】crt 无法上传文件,总是显示盾牌表示-完美解决
    【费元星原创】一键安装Hadoo2.7.6 集群完全分布式脚本-完美解决
    【研发工具必备】费元星的技术成长流线图-第一版
    【shell mysql 导出数据到csv脚本,完美解决乱码转义符等问题】-费元星
    【Linux搭建创建FTP服务器】---完美解决
  • 原文地址:https://www.cnblogs.com/healthy-tree/p/3169105.html
Copyright © 2011-2022 走看看