How to find out if ListView has scrolled to top Most position?

后端 未结 10 949
情歌与酒
情歌与酒 2020-12-29 03:09

I have a ListView, first its scrolled down, now when we scroll up,it reach top most point. I want to detect that .Is there any way?I am developing application with api level

10条回答
  •  萌比男神i
    2020-12-29 03:49

    edit

    See comments below as to why, especially on different API versions (esp later ones), this isn't a foolproof way to see if you're list is at the top (padding etc). However, it does give you a start for a solution on devices below API 14:

    private boolean listIsAtTop()   {   
        if(listView.getChildCount() == 0) return true;
        return listView.getChildAt(0).getTop() == 0;
    }
    

    As far as my implementation years ago - this worked perfectly at the time.

提交回复
热议问题