简体   繁体   English

知道列表视图何时滚动到顶部的任何方式?

[英]Any way of knowing when a listview has scrolled to top?

I'm trying to add a stikcy header to a listview. 我正在尝试为listview添加一个stikcy标头。 I've put the header-field and the listview inside a relativelayout and defined the listview's android:layout_below="@id/header". 我将header-field和listview放在relativelayout中,并定义了listview的android:layout_below =“@ id / header”。

The problem is that I want the listview and the header to be positioned at the same place when the listview is not scrolled to the top. 问题是,当列表视图未滚动到顶部时,我希望listview和标题位于同一位置。 The header's background is transparent. 标题的背景是透明的。 I drew an amazing image in paint to illustrate how I want them to interact. 我画了一幅令人惊叹的油画图片来说明我希望他们如何互动。

标题和ListView

I figured I could override the listviews onscrollistener and change the listviews layout_below-tingy at runtime when it's getScrollY() == 0, but that seems to happen all the time. 我想我可以覆盖listviews onscrollistener并在运行时更改listview layout_below-tingy,当它是getScrollY()== 0时,但这似乎一直在发生。

Has anyone done something similar that could point me in the right direction? 有没有人做过类似的事情,可以指出我正确的方向?

你可以尝试调用getFirstVisiblePosition

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM