如何在 Android 中创建 rtl GridLayoutManager?
How to create rtl GridLayoutManager in Android?
我正在 android 项目中创建一个 recyclerView
,我想在我的 recyclerView
中设置一个 gridLayout manager
。
这是我的代码:
workHourRecycler = view.findViewById(R.id.market_hours_recycler);
workHourRecycler.setLayoutManager(new GridLayoutManager(getContext(),4));
但是 GridLayout
必须是 'rtl direction'
谁知道?
谢谢。
试试这个
GridLayoutManager layoutManager = new GridLayoutManager(this, numberOfRows, GridLayoutManager.HORIZONTAL, true);
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2);
rvProductlist.setLayoutManager(mLayoutManager);
/**
* @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());
您需要以编程方式更改 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);
我正在 android 项目中创建一个 recyclerView
,我想在我的 recyclerView
中设置一个 gridLayout manager
。
这是我的代码:
workHourRecycler = view.findViewById(R.id.market_hours_recycler);
workHourRecycler.setLayoutManager(new GridLayoutManager(getContext(),4));
但是 GridLayout
必须是 'rtl direction'
谁知道?
谢谢。
试试这个
GridLayoutManager layoutManager = new GridLayoutManager(this, numberOfRows, GridLayoutManager.HORIZONTAL, true);
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2);
rvProductlist.setLayoutManager(mLayoutManager);
/**
* @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());
您需要以编程方式更改 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);