查看: 92|回复: 0

Android开发 layer-list开发例子

[复制链接]

3

主题

0

回帖

0

积分

热心网友

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2011-11-4
发表于 2019-8-8 15:21:00 | 显示全部楼层 |阅读模式

前言

  举例一些 layer-list  开发实用例子,用于拓展思维

 

底部带线条的正方形背景

方式一

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item  >
        <shape>
            <solid android:color="@color/color_blue" />
        </shape>

    </item>

    <!--  注意! item是相反的,蓝色线条应该在上面,黑色背景反而在下面  -->
    <item android:bottom="30dp">
        <shape >
            <solid android:color="@color/color_black"/>
        </shape>
    </item>


</layer-list>

效果图:

方式二

这种方式本质上是画一个空心矩形,但是使用关键属性:  android:bottom="0dp" android:left="-31dp" android:right="-31dp" android:top="-31dp"  这四个属性控制四条边是否显示出来

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="0dp"
        android:left="-31dp"
        android:right="-31dp"
        android:top="-31dp">
        <shape>
            <solid android:color="@android:color/holo_blue_bright" />
            <stroke
                android:width="30dp"
                android:color="#000000" />
            <padding android:bottom="4dp" />
        </shape>
    </item>

</layer-list>

效果图:

渐变色边框

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <gradient
                android:angle="270"
                android:startColor="#FBE650"
                android:endColor="#FFC215" />
            <corners android:radius="64dp" />
        </shape>
    </item>
    <item
        android:bottom="4dp"
        android:left="4dp"
        android:right="4dp"
        android:top="4dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
            <corners android:radius="64dp" />
        </shape>
    </item>

</layer-list>

效果图

实现竖虚线

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:left="-600dp"
        android:right="-600dp">
        <rotate
            android:fromDegrees="90"
            android:visible="true">
            <shape android:shape="line">
                <stroke
                    android:width="1dp"
                    android:color="@color/public_color_DFDFDF"
                    android:dashWidth="4dp"
                    android:dashGap="2dp" />

            </shape>
        </rotate>
    </item>
</layer-list>

 

效果图:

渐变色虚线

黑色为背景色,所以高度超出可以接受,因为无法看到

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:height="15dp" android:top="1dp">
        <shape>
            <gradient
                android:type="linear"
                android:angle="0"
                android:endColor="#002B23"
                android:startColor="#48F3D0" />
        </shape>
    </item>
    <item android:height="21dp" android:left="5dp" android:right="4dp">
        <shape android:shape="line">
            <stroke
                android:dashGap="15dp"
                android:dashWidth="20dp"
                android:width="20dp"
                android:color="#141414" />
        </shape>
    </item>
</layer-list>

效果图:

 

 

 

 

End

 

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部