如何解决如果添加了footerview,则分隔符将从列表视图中的最后一项消失
|| 如果在ListView中添加了页脚视图,则分隔符将从ListView的最后一项中消失。 甚至我已经用ListView设置了“ 0”,并且我的页脚视图就是TextTiew。解决方法
Android中的
ListView
实现从不在禁用的项目之间绘制分隔线,如果您只是调用addFooterView(View v)
方法,则默认情况下,页脚将为。
相反,您需要将isSelectable
设置为true
来调用addFooterView(View v,Object data,boolean isSelectable)
方法。如果不需要,可以只将ѭ6传递给data
对象。
,将isSelectable
设置为true
对我不起作用,这可能是因为在列表加载完成后,我也在呼叫removeFooterView
。
最终为我解决的是在ListView上将android:layout_height
设置为\“fill_parent
\”而不是\“wrap_content
\”。
,这几乎对我有用。我在最后一个列表项之后使用分隔符,但在页脚之后却没有,因为页脚是空白空间。我最终添加了两个页脚,其中一个可以选择零高度,另一个不能选择包含页脚。
TextView view = new TextView(this);
view.setLines(0);
TextView view1 = new TextView(this);
view1.setLines(4);
mListView.addFooterView(view,null,true);
mListView.addFooterView(view1,false);
mListView.setFooterDividersEnabled(true);
,尝试将ListView
中的layout_height
设置为match_parent
:
android:layout_width=\"match_parent\"
android:layout_height=\"match_parent\"
android:divider=\"#333333\"
android:dividerHeight=\"1px\"
当layout_height
设置为wrap_content
时,它可能会跳过底部的分隔线:
android:layout_width=\"match_parent\"
android:layout_height=\"wrap_content\"
android:divider=\"#333333\"
android:dividerHeight=\"1px\"
,穿墙方法是可靠的,但要手动将分隔线添加为页脚视图。
ListView myListView = (ListView) view.findViewById(R.id.my_list_view);
myListView.addFooterView(getInflater().inflate(R.layout.horizontal_divider,myListView,false),false);
myListView.addFooterView(getInflater().inflate(R.layout.the_original_footer_view,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
则没有。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。