layer-list:Android中layer-list使用详解
使用layer-list可以将多个drawable按照顺序层叠在一起显示,默认情况下,所有的item中的drawable都会自动根据它附上view的大小而进行缩放,
layer-list中的item是按照顺序从下往上叠加的,即先定义的item在下面,后面的依次往上面叠放
例子
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item >
<shape android:shape="rectangle" >
<solid android:color="#0000ff"/>
</shape>
</item> <item android:bottom="25dp" android:top="25dp" android:left="25dp" android:right="25dp">
<shape android:shape="rectangle" >
<solid android:color="#00ff00" />
</shape>
</item> <item android:bottom="50dp" android:top="50dp" android:left="50dp" android:right="50dp">
<shape android:shape="rectangle" >
<solid android:color="#ff0000" />
</shape>
</item>
</layer-list>
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:background="@drawable/layer_list"/>
</LinearLayout>
效果图

红色item最后定义在最上方,绿色item中间,最先定义蓝色最下边
这里设置了android:bottom="50dp" android:top="50dp" android:left="50dp" android:right="50dp"属性
android:top="50dp";表示该item上边以ImageView上边界往里面缩了50dp
android:bottom="50dp"表示该item下边以ImageView下边界往里面缩了50dp
android:left="50dp";表示该item左边以ImageView左边界往里面缩了50dp
android:right="50dp";表示该item右边以ImageView右边界往里面缩了50dp
android:bottom="25dp" android:top="25dp" android:left="25dp" android:right="25dp"类似
layer-list给指定view实现三面边框
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item >
<shape android:shape="rectangle" >
<solid android:color="#ff0000"/>
</shape>
</item> <item android:bottom="2dp" android:top="2dp" android:right="2dp">
<shape android:shape="rectangle" >
<solid android:color="#ffffff" />
</shape>
</item> </layer-list>
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <LinearLayout
android:layout_width="150dp"
android:layout_height="50dp"
android:background="@drawable/border"
android:layout_gravity="center"
android:orientation="vertical"
>
</LinearLayout>
</LinearLayout>
效果图

实现带阴影的按钮效果:

代码:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<!-- 灰色阴影 -->
<layer-list>
<item
android:left="2dp"
android:top="4dp">
<shape>
<solid android:color="@android:color/darker_gray" />
<corners android:radius="4dp" />
</shape>
</item> <!-- 红色前景 -->
<item
android:bottom="4dp"
android:right="2dp">
<shape>
<solid android:color="#FF0000" />
<corners android:radius="4dp" />
</shape>
</item>
</layer-list> </item> <item> <!-- 灰色阴影 -->
<layer-list>
<item
android:left="2dp"
android:top="4dp">
<shape>
<solid android:color="@android:color/darker_gray" />
<corners android:radius="4dp" />
</shape>
</item> <!-- 白色前景 -->
<item
android:bottom="4dp"
android:right="2dp">
<shape>
<solid android:color="#FFFFFF" />
<corners android:radius="4dp" />
</shape>
</item>
</layer-list> </item>
</selector>
<END>
layer-list:Android中layer-list使用详解的更多相关文章
- Android中Service的使用详解和注意点(LocalService)
Android中Service的使用详解和注意点(LocalService) 原文地址 开始,先稍稍讲一点android中Service的概念和用途吧~ Service分为本地服务(LocalServ ...
- Android中SurfaceView的使用详解
Android中SurfaceView的使用详解 http://blog.csdn.net/listening_music/article/details/6860786 Android NDK开发 ...
- Android中的windowSoftInputMode属性详解
这篇文章主要介绍了Android中的windowSoftInputMode属性详解,本文对windowSoftInputMode的9个属性做了详细总结,需要的朋友可以参考下 在前面的一篇文章中 ...
- Android中Canvas绘图基础详解(附源码下载) (转)
Android中Canvas绘图基础详解(附源码下载) 原文链接 http://blog.csdn.net/iispring/article/details/49770651 AndroidCa ...
- Android中Application类的详解:
Android中Application类的详解: 我们在平时的开发中,有时候可能会须要一些全局数据.来让应用中的全部Activity和View都能訪问到.大家在遇到这样的情况时,可能首先会想到自定义一 ...
- Android 中的消息传递,详解广播机制
--------------------------------------广播机制简介--------------------------------------------- Android中的广 ...
- Android中的sharedUserId属性详解
在Android里面每个app都有一个唯一的linux user ID,则这样权限就被设置成该应用程序的文件只对该用户可见,只对该应用程序自身可见,而我们可以使他们对其他的应用程序可见,这会使我们用到 ...
- Android中Activity启动模式详解
在Android中每个界面都是一个Activity,切换界面操作其实是多个不同Activity之间的实例化操作.在Android中Activity的启动模式决定了Activity的启动运行方式. An ...
- Android中数据库的操作流程详解
Android中数据库的操作方法: 1.Android平台提供了一个数据库辅助类来创建或打开数据库. 这个辅助类继承自SQLiteOpenHelper类.继承和扩展SQLiteOpenHelper类主 ...
- android中include标签使用详解
android中include标签是为了便于控件的覆用的一个很好解决方案. 但是也有一些需要注意的地方,下面是本人在项目中碰到过的一个问题,做此记录,便于以后查看. include标签用法. ...
随机推荐
- Linux特殊的文件控制权限FACL
对文件设置特殊的权限,FACL(File Access Control List) ACL简介 基本ACL操作 getfacl 查看文件权限 setfacl 设定acl权限 设置file ...
- H5商城,纯前端静态页面
发布时间:2018-09-28 技术:jquery1.10.1+swipeSlide+jquery.mmenu+jquery.touchSwipe+cityinit 概述 纯手写H5商城,2年 ...
- Ubuntu下,terminal经常使用快捷键
# ctrl + l - 清屏 . cLear # ctrl + c - 终止命令. # ctrl + d - 退出 shell,好像也能够表示EOF. # ctrl + r - 从命令历史中找 . ...
- Mac 升级 PHP 7
http://www.phpyc.com/article/15 mac 自带 php, 这个地球人都知道 在新系统中,/usr/bin 成为了系统保护目录,所以我们以前使用的替换 系统 php 的方法 ...
- linux创建用户名密码等操作
转自: https://www.linuxidc.com/Linux/2017-06/144916.htm 与大家分享下Linux系统中创建用户.设置密码.修改用户.删除用户的命令,希望对你有所帮助. ...
- 过滤IP地址的正则表达式
现场需求,过滤 指定IP段位的相关话单,收集看看用正则表达式怎么写, 原文地址:http://www.cnblogs.com/kongxianghai/p/3995463.html 检测IP地址的正则 ...
- 工作8年对技术学习过程的一些 总结 与 感悟 为什么有时迷茫、无奈 学习编程语言的最高境界最重要的是编程思想 T 字发展 学技术忌讳”什么都会“ 每天进步一点等式图 时间管理矩阵
工作这些年对技术学习过程的一些 总结 与 感悟(一) 引言 工作了8年,一路走来总有些感触时不时的浮现在脑海中.写下来留个痕迹,也顺便给大家一点参考.希望能给初学者一点帮助. 入门 进入计算机行业,起 ...
- Git 提交更新到仓库(分布式版本控制系统)
1.Git 文件生命周期 工作目录下的每一个文件都不外乎这两种状态:已跟踪或未跟踪. 已跟踪的文件是指那些被纳入了版本控制的文件,在上一次快照中有它们的记录,在工作一段时间后,它们的状态可能处于未修改 ...
- 【php】thinkphp以post方式查询时分页失效的解决方法
好久没有写博客了,最近说实话有点忙,各个项目都需要改bug.昨天晚上一直没有解决的php项目中的bug,就在刚才终于搞定,在这里还需要感谢博客园大神给的帮助! 具体问题描述 最近遇到一个非常棘手的问题 ...
- scala+hadoop+spark环境搭建
一.JDK环境构建 在指定用户的根目录下编辑.bashrc文件,添加如下部分: # .bashrc # Source global definitions if [ -f /etc/bashrc ]; ...