如果添加了页脚视图,分隔符将从列表视图中的最后一项消失
如果在 ListView 中添加页脚视图,则分隔符将从 ListView 的最后一项消失。
即使我已经设置了 android:footerDividersEnabled="true"
与 ListView 和我的页脚视图只是 TextTiew。
If footer view added in ListView, then divider disappears from last item of ListView.
Even I have set android:footerDividersEnabled="true"
with ListView and my footer view is just TextTiew.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将
isSelectable
设置为true
对我来说不起作用,可能是因为当我的列表加载完成时我还在调用removeFooterView
。最终为我解决的问题是将 ListView 上的
android:layout_height
设置为“fill_parent
”而不是“wrap_content
”。Setting
isSelectable
totrue
didn't work for me, maybe because I was also callingremoveFooterView
when my list was done loading.What finally fixed it for me was setting
android:layout_height
to "fill_parent
" instead of "wrap_content
" on the ListView.Android 中的
ListView
实现永远不会在禁用的项目之间绘制分隔线,如果您只是调用addFooterView(View v)
方法,那么默认情况下您的页脚将会如此。相反,您需要调用
addFooterView(View v, Object data, boolean isSelectable)
方法,并将isSelectable
设置为true
。如果不需要,您可以为data
对象传递null
。The
ListView
implementation in Android never draws dividers between items that are disabled, which if you are just calling theaddFooterView(View v)
method then by default your footer will be.Instead you need to call the
addFooterView(View v, Object data, boolean isSelectable)
method withisSelectable
set totrue
. You can just passnull
for thedata
object if you don't need it.这几乎对我有用。我在最后一个列表项之后的分隔线之后,但不在页脚之后,因为我的页脚是空白的。我最终添加了两个页脚,一个可选择零高度,一个不可选择包含填充。
This almost worked for me. I was after a divider after the last list item, but not after the footer as my footer was empty space. I ended up adding two footers, one selectable of zero height and one not selectable containing the padding.
尝试将
ListView
的layout_height
设置为match_parent
:当
layout_height
设置为wrap_content
时code> 它可能会跳过底部分隔线:Try setting the
layout_height
of theListView
tomatch_parent
:When the
layout_height
is set towrap_content
it might skip the bottom divider:穿墙而过的方法,但可靠的是,手动添加分隔线作为页脚视图。
布局文件如下所示:
这种方法可用于轻松添加分隔线,即使在最后一个页脚之后,无论它是可选的、启用的还是其他任何东西 - 它只是保留在那里。
请注意,高度是
1px
而不是1dp
。尽管与所有建议不同,至少在我测试的设备上,它提供了与 ListView 相同的分隔线高度,而1dp
则不然。Head through the wall approach, but reliable, is to manually add divider as a footer view.
Where the layout file would look like this:
This approach can be used to add the divider easily even after the last footer, regardless it is selectable, enabled or anything - it just stays there.
Note the height is
1px
rather than1dp
. Though against all recommendations, at least at the device I tested this gives the same divider height as ListView, while1dp
does not.