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

时间:2019-02-25 04:05:46

标签: android android-recyclerview

我们如何并行显示RecyclerView个项目。我尝试通过使用FlowLayoutManagerFlexboxLayoutManager来做到这一点,但是它仅以列表格式显示,这里是带有FlowLayoutManager的代码:

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

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

这是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);

我正在得到结果列表

但是我想这样

感谢您的帮助。

4 个答案:

答案 0 :(得分:1)

relayerview的linearlayoutmanager的设置方向

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

答案 1 :(得分:0)

尝试

setFlexDirection as Row Reverse

答案 2 :(得分:0)

请按照以下代码进行操作,并使适配器的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);

像这样添加到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" >

答案 3 :(得分:0)

使用ChipsLayoutManager 使用以下lib可以帮助我做同样的事情

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