zoukankan      html  css  js  c++  java
  • Android UI(一)Layout 背景局部Shape圆角设计

    Jeff Lee blog:   http://www.cnblogs.com/Alandre/  (泥沙砖瓦浆木匠),retain the url when reproduced ! Thanks

    今天我们来Android UI第一讲:实现Layout 背景局部Shape圆角设计

    效果图:

    image

    第一步:定义一个shape

    res/drawable/shape_to_corner_no_bottom_line.xml

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <item>
            <!-- shape with circle-top corner -->
            <shape>
                <!-- the shape background color -->
                <solid android:color="@color/black"/>
                <corners android:topLeftRadius="10dp" android:topRightRadius="10dp"
                    	 android:bottomLeftRadius="0.1dp" android:bottomRightRadius="0.1dp"/>
                <stroke  android:width="1dp" android:color="@color/black"/>
            </shape>
        </item>
    </layer-list>
    

    其中参数含义:{英语单词顾名思义}

    这是参数详解
    
     <!-- 圆角 -->
        <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"/>
        填充:设置填充的颜色
    
    间隔:设置四个方向上的间隔
    
    大小:设置大小
    
    圆角:同时设置五个属性,则Radius属性无效
    
    android:Radius="20dp"                           设置四个角的半径
    
    android:topLeftRadius="20dp"              设置左上角的半径
    android:topRightRadius="20dp"           设置右上角的半径
    android:bottomLeftRadius="20dp"      设置右下角的半径
    android:bottomRightRadius="20dp"    设置左下角的半径
    
    描边:dashWidth和dashGap属性,只要其中一个设置为0dp,则边框为实现边框
    
    android:width="20dp"                               设置边边的宽度
    android:color="@android:color/black"  设置边边的颜色
    android:dashWidth="2dp"                         设置虚线的宽度
    android:dashGap="20dp"                          设置虚线的间隔宽度

    渐变:当设置填充颜色后,无渐变效果。angle的值必须是45的倍数(包括0),仅在type="linear"有效,不然会报错。android:useLevel 这个属性不知道有什么用。

    第二步: Layout中设置

       android:background="@drawable/shape_to_corner_no_bottom_line"

    这样就简单的设置好了。

  • 相关阅读:
    默认组件加载类
    加密工具类
    客户端安全传输密码至服务端的实现改进
    开发Angular库的简单指导(译)
    Windows中搭建Redis集群
    Mybatis中SqlMapper配置的扩展与应用(3)
    Mybatis中SqlMapper配置的扩展与应用(2)
    Mybatis中SqlMapper配置的扩展与应用(1)
    优化与扩展Mybatis的SqlMapper解析
    使用XSD校验Mybatis的SqlMapper配置文件(2)
  • 原文地址:https://www.cnblogs.com/Alandre/p/4106807.html
Copyright © 2011-2022 走看看