首先,我们先来了解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的底部,也就不会出现分割线了。

posted on 2015-12-31 10:30  Jinger1992223  阅读(302)  评论(0编辑  收藏  举报