[英]Make Header View (not Section Header) of ListView Stick on Top
I have a ListView with a HeaderView. 我有一个带有HeaderView的ListView。
I want one of the views in the HeaderView
to stick on top. 我希望
HeaderView
中的一个视图能够粘在上面。
I've seen a lot of examples for sticky Section Headers. 我已经看到很多关于粘性节标题的例子。
I also looked at StickyScrollViewItems but since I'm using a ListView
, I cannot use a ScrollView
. 我也查看了StickyScrollViewItems,但由于我使用的是
ListView
,我无法使用ScrollView
。
Is there a library available for this or should I just override the OnScrollListener
of the ListView
? 是否有可用的库,或者我应该覆盖
ListView
的OnScrollListener
?
Thanks. 谢谢。
I don't know of any library that lets you do this but what I do for a header is to use a RelativeLayout
for my xml that will have the ListView
. 我不知道有任何库允许你这样做,但我为标题做的是使用
RelativeLayout
为我的xml将具有ListView
。 Then create your header view however you want and give it the property 然后根据需要创建标题视图并为其提供属性
android:layout_alignParentTop="true"
then give your ListView
然后给你的
ListView
android:layout_below="@id/idOfHeaderView
This is the easiest way I know of to dock a header view at the top. 这是我所知道的将标题视图停靠在顶部的最简单方法。 It has worked for me every time.
它每次都对我有用。 I hope this helps.
我希望这有帮助。
I have just written a load of code that does this that I cant share for contractoral reasons. 我刚刚编写了大量代码来执行此操作,但由于合同原因我无法共享。 Basically follow the approach outlined here and apply to a listview rather than a scroll view.
基本上遵循此处概述的方法并应用于列表视图而不是滚动视图。
Main points are 要点是
Remember to set the initial position of the floating/pinned header after the listview has been layed out. 在列出视图布局后,请记住设置浮动/固定标题的初始位置。
I feel its a little bit involved and takes some tweaking to get right - this is a time where i envy iOS and any iOS devs will think your slacking as it takes a while to implement :D 我觉得它有点牵扯并需要一些调整才能做到正确 - 这是我羡慕iOS的时候,任何iOS开发人员都会认为你需要一段时间才能实现松弛:D
All the Open libs out there at time of writing are using scroll views or list view headers. 在编写本文时,所有Open libs都使用滚动视图或列表视图标题。 This issue with these approaches are that list views recycle views (so unlike scroll views you cant just keep a ref to the dummy view) and also the current libs seem duplicate the sticky views using adapter
getView
methods and so on - which is no good for dynamic list view header views as they are not recycled and can only have one parent, so reparenting would be annoying (and in my case has a lot of functionality so I defo dont want to create two views of the same type and shoehorn the current libs to fit my solutions) 这些方法的问题在于列表视图循环视图(因此不像滚动视图那样只能保留对虚拟视图的引用),并且当前的库似乎使用适配器
getView
方法等重复粘贴视图 - 这对于动态列表视图标题视图,因为它们不被回收,只能有一个父级,所以重新定位会很烦人(在我的情况下有很多功能,所以我不想创建两个相同类型的视图,并且当前的libs)适合我的解决方案)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.