Center a ListView on its current selection

前端 未结 3 1708
故里飘歌
故里飘歌 2021-02-08 10:16

Does anyone know of a way to center a ListView based on its current selection or selection set with setSelection?

I did see this other StackOverflow question without any

3条回答
  •  天涯浪人
    2021-02-08 10:25

    You will need to have the scroll view and the view of the item selected. Then you can simply do:

    scrollView.smoothScrollTo(0, selectedView.getTop() - (scrollView.getHeight() / 2) + (selectedView.getHeight() / 2), 0);
    

    This will center the scroll view exactly on selectedView

提交回复
热议问题