Android support v4 SwipeRefreshLayout empty view issue

后端 未结 9 1207
耶瑟儿~
耶瑟儿~ 2021-01-01 18:01

SwipeRefresh is not working after setting an empty view for listview which is the only child of a SwipeRefresh layout. How to solve this issue?

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 18:35

    here's how i did this (probably not very elegant solution)

    private void createEmptyView() {
        ViewGroup parent = (ViewGroup) listView.getParent();
        emptyView = (TextView) getLayoutInflater(null)
                .inflate(R.layout.view_empty, parent, false);
        parent.addView(emptyView);
        listView.setEmptyView(emptyView);
    }
    
    public class FrameSwipeRefreshLayout extends SwipeRefreshLayout {
    
        private ViewGroup listView;
        public void setListView(ViewGroup list) {
            listView = list;
        }
    
        @Override
        public boolean canChildScrollUp() {
            if (listView != null) {
                View child = listView.getChildAt(0);
                return child != null && child.getTop() != 0;
            }
            return super.canChildScrollUp();
        }
    }
    

    empty layout

    
    

    list layout

        
            
            
            
        
    

提交回复
热议问题