How to get the first visible View from an Android ListView

前端 未结 6 1322
情歌与酒
情歌与酒 2021-01-04 15:22

Is there a way to get the first visible View out of the ListView in Android?

I can get the data that backs the first View in the Adapter but it seems I can\'t get t

6条回答
  •  南笙
    南笙 (楼主)
    2021-01-04 16:20

    Indeed listView.getChildAt(listView.getFirstVisiblePosition()) gives the first visible item,
    BUT it could be half visible list item.

    To get first completely visible list item,

    if (listView.getChildAt(0).getTop() < 0) {
         int firstCompletelyVisiblePos = listView.getFirstVisiblePosition() + 1;
    }
    

提交回复
热议问题