ListView实现item的卡片效果(不使用RecyclerView+CardView)

来源:互联网 发布:微信使用什么端口 编辑:程序博客网 时间:2024/04/28 16:39

现在网上有很多漂亮的listView的显示效果,度娘会告诉你其实很简单不就是用RecyclerView和CardView就实现了嘛,结果代码除了一大串,对于初学者绝对就晕了,技术是死的认识活的,接下来我就使用样式来为大家实现(也可以自己绘制,但是更麻烦!慎用!)
这里写图片描述

想必大家对shape、selector都是十分的熟悉了,接下来咱们使用layer-list在写样式

 <!-- 阴影部分 -->      <!-- top代表下边的阴影高度,left代表右边的阴影宽度。其实也就是相对应的offset,solid中的颜色是阴影的颜色,也可以设置角度等等 -->      <item          android:left="2dp"          android:top="2dp">          <shape android:shape="rectangle" >              <gradient                  android:angle="270"                  android:endColor="#0F000000"                  android:startColor="#0F000000" />              <corners                  android:bottomLeftRadius="6dip"                  android:bottomRightRadius="6dip"                  android:topLeftRadius="6dip"                  android:topRightRadius="6dip" />          </shape>      </item>      <!-- 背景部分 -->      <!--bottom代表背景部分在上边缘超出阴影的高度,right代表背景部分在左边超出阴影的宽度(相对应的offset) -->      <item          android:bottom="3dp"          android:right="3dp">          <shape android:shape="rectangle" >              <gradient                  android:angle="270"                  android:endColor="#FFFFFF"                  android:startColor="#FFFFFF" />              <corners                  android:bottomLeftRadius="6dip"                  android:bottomRightRadius="6dip"                  android:topLeftRadius="6dip"                  android:topRightRadius="6dip" />          </shape>      </item>  

只需要在你items的布局下设置background即可,listView设置divider=“@null“属性,去除items分割线
这样就实现了效果,是不是更简单!

2 0