开发者

Do ListView's getFirstVisiblePosition and getLastVisiblePosition lie?

开发者 https://www.devze.com 2023-01-08 17:44 出处:网络
I\'ve got my ListView on screen.It\'s scrolled to the top.I see 6 rows.开发者_如何学GoAnd when I Log getFirstVisiblePosition() and getLastVisiblePosition(), it says 0 and 6.

I've got my ListView on screen. It's scrolled to the top. I see 6 rows. 开发者_如何学GoAnd when I Log getFirstVisiblePosition() and getLastVisiblePosition(), it says 0 and 6.

Is getLastVisiblePosition() actually returning the first non-visible position? In other words, should my test for whether a particular row is onscreen be not

first <= row && row <= last

but rather

first <= row && row < last

?


Well, probably there is the portion of last visible view number 6 in your case, that is actually detected as visible (maybe just a tiny part appears on the bottom of the screen). But in any case if it shows that the count is 7, why not go with it? I mean whatever you do to that row won't actually be seen, plus the view is already bound in the adapter and the getView method in the adapter wont be called again.

One more thing with your second code is that, for example, when you have only one view then the first will be 0, row will be 0 and last will be 0 and your conditions won't be met. Don't know if this helps you in any way but still...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号