简体   繁体   English

如何并排显示回收者视图项目

[英]How to display recycler view items side by side

How can we display RecyclerView items side by side. 我们如何并排显示RecyclerView项目。 i tried to do this by using FlowLayoutManager and FlexboxLayoutManager but it is showing in list format only here is the code with FlowLayoutManager : 我试图通过使用FlowLayoutManagerFlexboxLayoutManager来做到这一点,但它仅以列表格式显示,这里是FlowLayoutManager的代码:

  FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
  flowLayoutManager.setAutoMeasureEnabled(true);
    listView.setLayoutManager(flowLayoutManager);

    madapter = new testingAdapter(Quran_e_Kareem.this,surah1);
    listView.setAdapter(madapter); 

here is the code with FlexboxLayoutManager: 这是FlexboxLayoutManager的代码:

    FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(getApplicationContext());
    //         Set flex direction.
    flexboxLayoutManager.setFlexDirection(FlexDirection.ROW);
    flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP);
    flexboxLayoutManager.setAlignItems(AlignItems.FLEX_START);
    flexboxLayoutManager.setJustifyContent(JustifyContent.FLEX_START);
    listView.setLayoutManager(flexboxLayoutManager);

madapter = new testingAdapter(Quran_e_Kareem.this,surah1);
listView.setAdapter(madapter);

I am getting result list this 我正在得到结果清单

But i want to get this way 但是我想这样

Any help is appreciated. 任何帮助表示赞赏。

为recyclerview设置linearlayoutmanager的方向

LinearLayoutManager layoutManager = LinearLayoutManager(activity,RecyclerView.HORIZONTAL,false)

尝试这个

setFlexDirection as Row Reverse

Please follow the below code and make your adapter textview wrap content may it will solve your problem. 请遵循以下代码,并使您的适配器textview换行内容可以解决您的问题。

        RecyclerView recyclerView = (RecyclerView)findViewById(R.id.flex_box_recycler_view);

        // Create the FlexboxLayoutMananger, only flexbox library version 0.3.0 or higher support.
        FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(getApplicationContext());

        // Set flex direction.
        flexboxLayoutManager.setFlexDirection(FlexDirection.ROW);

        // Set JustifyContent.
        flexboxLayoutManager.setJustifyContent(JustifyContent.SPACE_AROUND);
        recyclerView.setLayoutManager(flexboxLayoutManager);

Add into xml like this: 像这样添加到xml中:

<com.google.android.flexbox.FlexboxLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:flexWrap="wrap"
    app:alignItems="stretch"
    app:alignContent="stretch" >

使用ChipsLayoutManager使用以下lib可以帮助我执行相同操作

 implementation 'com.beloo.widget:ChipsLayoutManager:0.3.7@aar'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM