码迷,mamicode.com
首页 > 移动开发 > 详细

Android资源文件-Shape

时间:2016-04-19 12:25:36      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:

  1. solid
    技术分享
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <!--绿色填充-->
    <solid android:color="#0f0" />

</shape>

2.corner
技术分享

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#0f0" />
    <!--半径为10px的圆角-->
    <corners android:radius="10px" />

</shape>

3.gradient
技术分享

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#0f0" />

    <corners android:radius="10px" />
     <!--渐变色:开始的颜色,中间的颜色,结束的颜色-->
    <gradient
        android:startColor="#D8FC83"
        android:centerColor="#41F114"
        android:endColor="#0f0"
        />

</shape>

4.stroke
技术分享

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#0f0" />

    <corners android:radius="10px" />

    <gradient
        android:centerColor="#41F114"
        android:endColor="#0f0"
        android:startColor="#D8FC83" />
    <!--边框:宽度,颜色-->
    <stroke
        android:width="1px"
        android:color="#f0f" />

</shape>

5.阴影效果
技术分享

需要3个图层:
a:最底层和整体背景颜色一致
b:中间层left和top错开2dp
c:最上层和阴影颜色一致的边框,和最底层一样颜色的填充色,bottom和right方向错开2dp
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <!--最底层-->
    <item>
        <shape>
            <solid android:color="#fff" />
        </shape>
    </item>
  <!--中间层-->
    <item
        android:left="2dp"
        android:top="2dp">
        <shape>
            <solid android:color="#ccc" />
        </shape>
    </item>
  <!--最上层-->
    <item
        android:bottom="2dp"
        android:right="2dp">
        <shape>
            <solid android:color="#fff" />

            <stroke
                android:width="1px"
                android:color="#ccc" />
        </shape>
    </item>
</layer-list>

6.底部边框颜色和其它边框颜色不同。
技术分享–>技术分享–>技术分享

a:最底层黄色填充色。
b:中间层灰色边框1px,白色填充色,bottom 5px,可以露出5px的底层的黄色。
c:最上层left,right,top透明边框1px,白色填充色,正好显示出中间层的left,right,top边框。bottom 4px正好覆盖中间层的底部边框。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!--第一层-->
    <item>
        <shape>
            <solid android:color="#ff0" />
        </shape>
    </item>
<!--第二层-->
    <item android:bottom="5px">
        <shape>
            <solid android:color="#fff" />
            <stroke
                android:width="1px"
                android:color="#ccc" />
        </shape>
    </item>
为了去掉底部灰色边框,再覆盖一个图层。(白色背景,透明边框,和第二层边框的width基本一致,但bottom的值一定要小于第二层的bottom值)
<!--第三层-->
    <item
        android:bottom="4px"
        android:left="1px"
        android:right="1px"
        android:top="1px">
        <shape>
            <solid android:color="#fff" />
            <stroke
                android:width="1px"
                android:color="#0000" />
        </shape>
    </item>
</layer-list>

Android资源文件-Shape

标签:

原文地址:http://blog.csdn.net/limiao2143/article/details/51182012

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!