1

I have a recylcer view having grid images and I have a button at the bottom of the recycler view. This button should be at the bottom of the recyclerview, not the bottom of the parent.

I tried code for recyclerView. But the button stays as parent bottom not scrolling along with the recycler view.

<android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="@string/hello_blank_fragment"/>
jophab
  • 5,356
  • 14
  • 41
  • 60
neena
  • 551
  • 1
  • 8
  • 24

2 Answers2

1

I have found the solution.

I can create a separate view with Button and can add in the recyclerView Adapter.But there will be one problem - Since My Layout manager is GridLayout manager and having span of 2, I have to change the span to 1 when the current view is Button.

The changing of span when the view is Button is below:

final GridLayoutManager mGridManager = new GridLayoutManager(getActivity(),2);

mGridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
        return adapter.isPositionHeader(position) ? mGridManager.getSpanCount() : 1;
    }
});
recyclerView.setLayoutManager(mGridManager);
recyclerView.setAdapter(adapter);

This code I had to add in recyclerView Adapter, this below code means when button is the view return true, otherwise return false

public boolean isPositionHeader(int position) {
    if(ADD_SOURCE_BUTTON == getItemViewType(position)){
        return true;
    } else {
        return false;
    }
}
Jaydip
  • 592
  • 5
  • 27
neena
  • 551
  • 1
  • 8
  • 24
0

Am not sure this is a good method, but it worked for me. Try putting RecyclerView inside a ScrollView and place the button below RecyclerView. It will work fine now. Earlier it had some issues of scrolling but now its fixed by google I think and we can place RecyclerView inside scroll view, but am not sure its a good method, but it will work.

Nivedh
  • 971
  • 1
  • 8
  • 19