Reputation: 6021
The problem is that all items show one item per row. like this:
| item |
| item |
| item |
I want to show them like this:
| item item |
| item |
| |
I have explicity set the width of items to 148dp. It was working fine in GridLayoutManager when column span was 2 or dynamic column per row based on their width to show as many as the screen width but there I could not center them easily.
After FlexLayoutManager I got this problem. Although when I set the direction to COLUMN the items show attached to left side but still on each row. I have this RealmRecycleView:
<co.moonmonkeylabs.realmrecyclerview.RealmRecyclerView
android:id="@+id/recycleViewDashboard"
android:layout_width="match_parent"
android:padding="@dimen/grid_item_offset"
android:clipToPadding="false"
android:layout_height="wrap_content"
app:rrvIsRefreshable="false"
app:rrvLayoutType="LinearLayout">
</co.moonmonkeylabs.realmrecyclerview.RealmRecyclerView>
and this is where I set the LayoutManager
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(getContext());
layoutManager.setFlexDirection(FlexDirection.ROW);
layoutManager.setJustifyContent(JustifyContent.SPACE_AROUND);
mRecyclerView.getRecycleView().setLayoutManager(layoutManager);
and this is my ItemView:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image_view"
android:layout_centerInParent="true"
android:layout_width="148dp"
android:layout_height="148dp"
android:background="#ccc"
android:scaleType="fitXY" />
</RelativeLayout>
Upvotes: 0
Views: 2388
Reputation: 11
Use :
layoutManager.setFlexDirection(FlexDirection.ROW);
layoutManager.setJustifyContent(JustifyContent.FLEX_START);
layoutManager.setAlignContent(AlignContent.CENTER);
layoutManager.setAlignItems(AlignItems.CENTER);
Upvotes: 1