如果添加了页脚视图,分隔符将从列表视图中的最后一项消失

发布于 2024-11-01 10:03:44 字数 150 浏览 6 评论 0原文

如果在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一笑百媚生 2024-11-08 10:03:44

isSelectable 设置为 true 对我来说不起作用,可能是因为当我的列表加载完成时我还在调用 removeFooterView

最终为我解决的问题是将 ListView 上的 android:layout_height 设置为“fill_parent”而不是“wrap_content”。

Setting isSelectable to true didn't work for me, maybe because I was also calling removeFooterView 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.

喜你已久 2024-11-08 10:03:44

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 the addFooterView(View v) method then by default your footer will be.

Instead you need to call the addFooterView(View v, Object data, boolean isSelectable) method with isSelectable set to true. You can just pass null for the data object if you don't need it.

旧时浪漫 2024-11-08 10:03:44

这几乎对我有用。我在最后一个列表项之后的分隔线之后,但不在页脚之后,因为我的页脚是空白的。我最终添加了两个页脚,一个可选择零高度,一个不可选择包含填充。

TextView view = new TextView(this);
view.setLines(0);
TextView view1 = new TextView(this);
view1.setLines(4);
mListView.addFooterView(view, null, true);
mListView.addFooterView(view1, null, false);
mListView.setFooterDividersEnabled(true);

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.

TextView view = new TextView(this);
view.setLines(0);
TextView view1 = new TextView(this);
view1.setLines(4);
mListView.addFooterView(view, null, true);
mListView.addFooterView(view1, null, false);
mListView.setFooterDividersEnabled(true);
谈场末日恋爱 2024-11-08 10:03:44

尝试将 ListViewlayout_height 设置为 match_parent

android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#333333"
android:dividerHeight="1px"

layout_height 设置为 wrap_content 时code> 它可能会跳过底部分隔线:

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#333333"
android:dividerHeight="1px"

Try setting the layout_height of the ListView to match_parent:

android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#333333"
android:dividerHeight="1px"

When the layout_height is set to wrap_content it might skip the bottom divider:

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#333333"
android:dividerHeight="1px"
感情洁癖 2024-11-08 10:03:44

穿墙而过的方法,但可靠的是,手动添加分隔线作为页脚视图。

ListView myListView = (ListView) view.findViewById(R.id.my_list_view);
myListView.addFooterView(getInflater().inflate(R.layout.horizontal_divider, myListView, false), null, false);
myListView.addFooterView(getInflater().inflate(R.layout.the_original_footer_view, myListView, false), null, false);

布局文件如下所示:

<View xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="1px"
    android:background="?android:attr/dividerVertical" />

这种方法可用于轻松添加分隔线,即使在最后一个页脚之后,无论它是可选的、启用的还是其他任何东西 - 它只是保留在那里。

请注意,高度是 1px 而不是 1dp。尽管与所有建议不同,至少在我测试的设备上,它提供了与 ListView 相同的分隔线高度,而 1dp 则不然。

Head through the wall approach, but reliable, is to manually add divider as a footer view.

ListView myListView = (ListView) view.findViewById(R.id.my_list_view);
myListView.addFooterView(getInflater().inflate(R.layout.horizontal_divider, myListView, false), null, false);
myListView.addFooterView(getInflater().inflate(R.layout.the_original_footer_view, myListView, false), null, false);

Where the layout file would look like this:

<View xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="1px"
    android:background="?android:attr/dividerVertical" />

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 than 1dp. Though against all recommendations, at least at the device I tested this gives the same divider height as ListView, while 1dp does not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文