您的位置:首页 > 移动开发 > Android开发

Android layer-list的使用

2016-01-18 17:06 399 查看
layer是在PS中非常常用的功能,是用来多个图层堆叠显示的。接下来做一个简单的例子:





点击左边条目 显示不同的背景。

正常时候的背景

<?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="#e5e5e5" />
</shape>
</item>
//底部上移1dp  右边左移1dp  显示黑色线条
<item android:right="1dp" android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#f2f3f5"/>
</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">
<solid android:color="#e5e5e5" />
</shape>
</item>
//底部上移1dp  右边没有
<item android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</item>
</layer-list>


再写一个selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/selected" android:state_selected="true"></item>
<item android:drawable="@drawable/normal"></item>

</selector>


然后设置为背景,就可以实现上图的效果。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: