如何在Android中创建rtl GridLayoutManager?

时间:2018-04-19 11:15:02

标签: android android-layout android-recyclerview recyclerview-layout

我在Android项目中创建recyclerView,我想在gridLayout manager中设置recyclerView

这是我的代码:

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

但是GridLayout必须'rtl direction'有人有想法吗?

感谢。

4 个答案:

答案 0 :(得分:1)

您需要以编程方式更改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);

答案 1 :(得分:0)

试试这个

GridLayoutManager layoutManager = new GridLayoutManager(this, numberOfRows, GridLayoutManager.HORIZONTAL, true);

答案 2 :(得分:0)

GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2);
rvProductlist.setLayoutManager(mLayoutManager);

答案 3 :(得分:0)

/**
 * @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());