[英]How to display recycler view items side by side
我們如何並排顯示RecyclerView
項目。 我試圖通過使用FlowLayoutManager
和FlexboxLayoutManager
來做到這一點,但它僅以列表格式顯示,這里是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);
我正在得到結果清單
但是我想這樣
任何幫助表示贊賞。
為recyclerview設置linearlayoutmanager的方向
LinearLayoutManager layoutManager = LinearLayoutManager(activity,RecyclerView.HORIZONTAL,false)
嘗試這個
setFlexDirection as Row Reverse
請遵循以下代碼,並使您的適配器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" >
使用ChipsLayoutManager使用以下lib可以幫助我執行相同操作
implementation 'com.beloo.widget:ChipsLayoutManager:0.3.7@aar'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.