Android ViewPager get the current View

前端 未结 15 2407
天命终不由人
天命终不由人 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:30

    is that your first activity on the screen or have you layered some above each other already?

    try this:

    findViewById(android.R.id.content).getRootView()
    

    or just:

    findViewById(android.R.id.content) 
    

    also depending on what you want try:

    ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0)
    

提交回复
热议问题