当前位置: 移动技术网 > 移动技术>移动开发>Android > 去掉ListView底部的ListDivider的方法

去掉ListView底部的ListDivider的方法

2019年07月24日  | 移动技术网移动技术  | 我要评论

首先,我们先来了解listview的两个属性以及它们的api解析

android:headerdividersenabled:when set to false, the listview will not draw the divider after each header view. [boolean]

android:footerdividersenabled:when set to false, the listview will not draw the divider before each footer view. [boolean]

可见,这里两个属性都只对headerview和footerview有效,如果你没有在listview加入headerview或者footerview,无论设置什么值,都是没有作用的。

那在我们该怎么让listview的底部divider消失呢,那就得在listview的layoutheight上做文章了。

通过对listview的源码分析,我们发现,所有的分割线都是通过画一个很窄的矩形实现的,但是在给每一行画分割线之前,listview都会判断当前行的底部位置是否到达或者超出了listview的底部,如果到达了,那么就不会画这条分割线。

所以,如果listview的高度是fill_parent,那么当item很少,而没有能填满listview的高度的时候,底部就会出现分割线。反之,如果listview的高度是wrap_content,那么listview的高度就是随着item的增多而变高的,最后一行的item始终是达到了listview的底部,也就不会出现分割线了。

以上这篇去掉listview底部的listdivider的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网