2

I'm creating a recyclerView in android project and i want to set a gridLayout manager in my recyclerView .

here is my Code :

workHourRecycler = view.findViewById(R.id.market_hours_recycler);
workHourRecycler.setLayoutManager(new GridLayoutManager(getContext(),4));

But GridLayout must be 'rtl direction' anyone have idea ?

Thanks.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Mehdi bahmanpour
  • 574
  • 7
  • 21

4 Answers4

5

You need to programmatically change the layout direction of the RecycleView

workHourRecycler = view.findViewById(R.id.market_hours_recycler);
workHourRecycler.setLayoutManager(new GridLayoutManager(getContext(),4));

//Programtically set the direction
workHourRecycler.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
Burhanuddin Rashid
  • 5,260
  • 6
  • 34
  • 51
1
/**
 * @param context Current context, will be used to access resources.
 * @param spanCount The number of columns or rows in the grid
 * @param orientation Layout orientation. Should be {@link #HORIZONTAL} or {@link
 *                      #VERTICAL}.
 * @param reverseLayout When set to true, layouts from end to start.
 */ 



RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getActivity(), 4, GridLayoutManager.HORIZONTAL, true);
rv_days.setLayoutManager(mLayoutManager);
rv_days.setItemAnimator(new DefaultItemAnimator());
Jyot
  • 540
  • 5
  • 17
0

Try this

GridLayoutManager layoutManager = new GridLayoutManager(this, numberOfRows, GridLayoutManager.HORIZONTAL, true);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
hasan_shaikh
  • 1,434
  • 1
  • 15
  • 38
0
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2);
rvProductlist.setLayoutManager(mLayoutManager);
Gautam Surani
  • 1,136
  • 10
  • 21
  • 2
    Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made. – Maximilian Peters Apr 19 '18 at 14:29