0

I have a RecyclerView with GridLayoutManager and when using SwipeRefreshLayout the RecyclerView is not pulled down. How to create the effect of having a gap between the toolbar and the recyclerview while refreshing?

XML:

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RecyclerView
            android:id="@+id/gridView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.v4.widget.SwipeRefreshLayout>

</FrameLayout>

CODE:

swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);

gridView = (RecyclerView) getActivity().findViewById(R.id.gridView);
gridLayoutManager = new GridLayoutManager(getActivity(), 4, GridLayoutManager.VERTICAL, false);
gridView.setLayoutManager(gridLayoutManager);
gridView.setVisibility(View.GONE);
gridView.setHasFixedSize(false);
gridView.setItemAnimator(new DefaultItemAnimator());
Luciano Rodríguez
  • 2,239
  • 3
  • 19
  • 32
mthandr
  • 3,062
  • 2
  • 23
  • 33
  • What have u tried? may be paste your xml layout code? – Asif Mujteba Apr 22 '15 at 17:53
  • I posted the code, but it is the simplest implementation with both of these two views. I think the problem resides in the GridLayoutManager, but I am not sure – mthandr Apr 22 '15 at 18:02
  • does that help? http://stackoverflow.com/questions/25178329/recyclerview-and-swiperefreshlayout – Asif Mujteba Apr 22 '15 at 18:12
  • no, because mine doesn't even move down. The refresh works, and the refresh view shows up, but on top of the grid, the grid does not move. – mthandr Apr 22 '15 at 18:13
  • Try adding it inside linear vertical layout – amodkanthe Apr 22 '15 at 18:23
  • doesn't change anything, and also the child of a swiperefreshlayout should be scrollable – mthandr Apr 22 '15 at 18:27
  • the grid is not supposed to move either.. just the refresh icon would move down and up, for demo check this: https://www.youtube.com/watch?v=nl8czoZtXVE :) – Asif Mujteba Apr 22 '15 at 18:27
  • Is pull to refresh working and only pull down effect is not there. In that case if you are using latest appcompat library it is not going to work. View can't be pull down in latest appcompat check gmail app – amodkanthe Apr 22 '15 at 18:30
  • it's true. Didn't know this, should have checked the app. The usual behavior in all apps is to pull down, I guess Google does not agree, so I will stick with it. Thanks to you both – mthandr Apr 22 '15 at 18:34
  • Yeah thats what u call Google's innovation :) I have added it as an answer.. – Asif Mujteba Apr 22 '15 at 18:41

1 Answers1

2

Your code is all okay, but the swipeRefreshLayout does not pull down the grid view but only itself, For the demo check this video. You can however use other libraries like Ulta-Pull-to-Refresh to achieve the desired effect!

Asif Mujteba
  • 4,596
  • 2
  • 22
  • 38