Can't scroll in a ListView in a swipeRefreshLayout

蹲街弑〆低调 提交于 2019-11-27 02:46:20

问题


I'm having an issue with the SwipeRefreshLayout. I have a list view within the layout and every time I scroll upward in the list view the swipe to refresh layout is tiggered and you can never scroll back to the top of the layout. Anyone have any ideas?


回答1:


I found an answer to my question. I am manually enabling the swipeRefreshLayout when the first child in the listview is at the top of the list.

    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView listView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            int topRowVerticalPosition = (listView == null || listView.getChildCount() == 0) ?
                            0 : expandableListview.getChildAt(0).getTop();
            refresh.setEnabled((topRowVerticalPosition >= 0));
        }
    });



回答2:


https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html

According to Android docs at the above link,

This layout should be made the parent of the view that will be refreshed as a result of the gesture and can only support one direct child.

If the ListView is the 1st direct child of the SwipeRefreshLayout, refresh won't be triggered before scrolling back to the top of the ListView. You don't need to do anything in onScroll().



来源:https://stackoverflow.com/questions/27041416/cant-scroll-in-a-listview-in-a-swiperefreshlayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!