Scroll up does not work with SwipeRefreshLayout in Listview

后端 未结 10 1444
失恋的感觉
失恋的感觉 2020-12-01 10:36

I want to implement scroll to refresh functionality with a listView. Also there are other view elements in the same layout file which are displayed if the list is empty. Her

10条回答
  •  隐瞒了意图╮
    2020-12-01 10:56

    In order for SwipeRefreshLayout to work, it needs to be the direct parent of your ListView, and the ListView should be the first active child view of the SwipeRefreshLayout.

    The documentation for SwipeRefreshLayout says that the ListView should be the only child, but it is okay if it has more than one child as long as the ListView is first. This means, for instance, that SwipeRefreshLayout will work fine if you are using an adapter with a view for "empty". For example:

    
    
        
    
        
    
    
    

    If you can manage this sort of layout, then SwipeRefreshLayout will work fine and you won't need any of the workarounds listed in other answers.

    My own problem was that that I was loading my ListView as a Fragment, so I actually had:

    
    
                   )
                     \ fragment
                     /
                  )
    
    
    

    So the SwipeRefreshLayout was choosing the FrameLayout as it's "target" and its default canChildScrollUp() implementation was always returning false. Once I moved the SwipeRefreshLayout inside the Fragment, everything started working correctly.

    
    
            )
                     \ fragment
                     /
           )
    
    
    

提交回复
热议问题