Android ViewPager get the current View

前端 未结 15 2332
天命终不由人
天命终不由人 2020-11-28 06:24

I have a ViewPager, and I\'d like to get the current selected and visible view, not a position.

  1. getChildAt(getCurrentItem) returns wrong Vi
相关标签:
15条回答
  • 2020-11-28 06:44

    If you examine carefully, there are at most 3 views saved by ViewPager. You can easily get the current view by

    view     = MyActivity.mViewPager.getChildAt(1);
    
    0 讨论(0)
  • 2020-11-28 06:50

    I just came across the same issue and resolved it by using:

    View view = MyActivity.mViewPager.getFocusedChild();
    
    0 讨论(0)
  • 2020-11-28 06:50

    I'm using ViewPagerUtils from FabulousFilter:

    ViewPagerUtils.getCurrentView(ViewPager viewPager)
    
    0 讨论(0)
提交回复
热议问题