【问题标题】:How to create rtl GridLayoutManager in Android? [duplicate]如何在 Android 中创建 rtl GridLayoutManager? [复制]
【发布时间】:2018-04-19 11:15:01
【问题描述】:

我正在 android 项目中创建一个recyclerView,我想在我的recyclerView 中设置一个gridLayout manager。

这是我的代码:

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

但是GridLayout 必须是'rtl direction' 有人知道吗?

谢谢。

【问题讨论】:

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


    【解决方案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);
    

    【讨论】:

    • 不错的解决方案!谢谢
    • 成功了??
    • 是的,就像一个魅力!
    【解决方案2】:
    /**
     * @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());
    

    【讨论】:

      【解决方案3】:
      GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2);
      rvProductlist.setLayoutManager(mLayoutManager);
      

      【讨论】:

      • 感谢您提供此代码 sn-p,它可能会提供一些有限的即时帮助。正确的解释将通过说明为什么这是解决问题的好方法,将大大提高其长期价值,并使其对有其他类似问题的未来读者更有用。请编辑您的答案以添加一些解释,包括您所做的假设。
      【解决方案4】:

      试试这个

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-20
        • 2014-09-04
        • 2013-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-02
        • 1970-01-01
        相关资源
        最近更新 更多