RecyclerView and SwipeRefreshLayout

后端 未结 12 1928
再見小時候
再見小時候 2020-12-22 15:46

I\'m using the new RecyclerView-Layout in a SwipeRefreshLayout and experienced a strange behaviour. When scrolling the list back to the top sometim

12条回答
  •  没有蜡笔的小新
    2020-12-22 16:12

    Here's one way to handle this, which also handles ListView/GridView.

    public class SwipeRefreshLayout extends android.support.v4.widget.SwipeRefreshLayout
      {
      public SwipeRefreshLayout(Context context)
        {
        super(context);
        }
    
      public SwipeRefreshLayout(Context context,AttributeSet attrs)
        {
        super(context,attrs);
        }
    
      @Override
      public boolean canChildScrollUp()
        {
        View target=getChildAt(0);
        if(target instanceof AbsListView)
          {
          final AbsListView absListView=(AbsListView)target;
          return absListView.getChildCount()>0
                  &&(absListView.getFirstVisiblePosition()>0||absListView.getChildAt(0)
                  .getTop()

提交回复
热议问题