Android RecyclerView LayoutManager - 1st item one column, rest of items as rows in 2nd column

37 Views Asked by At

Is it possible to layout RecyclerView items with some Layout Manager as on the picture? 1st column is 1st item, rest of items as rows in 2nd column? enter image description here

1

There are 1 best solutions below

2
TIMBLOCKER On

With your RecyclerView Setup, this is unfortunately not possible. But you could achieve the Image up top als follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="horizontal"
tools:context=".MainActivity2">

<androidx.cardview.widget.CardView
    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="5dp"
    android:layout_weight="1"
    app:cardBackgroundColor="#673AB7"
    app:cardCornerRadius="10dp"
    app:cardElevation="5dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<androidx.recyclerview.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndtOf="@+id/cardView"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</LinearLayout>

In your RecyclerView you can create a CustomAdapter that displays your Entries as CardView Rows. Then you determine the Average of your Contents and display them on the left. This is also far more reliable, beacuse you can determine the contents of the CardView without having conection to the RecyclerView. If you want to have everthing scrollable, you can wrap the LinearLayout in a ScrollView.