RecyclerView GridLayoutManager span size for 3 elements

52 Views Asked by At

I have this code:

(binding.photos.layoutManager as GridLayoutManager).spanSizeLookup =
            object : GridLayoutManager.SpanSizeLookup() {
                override fun getSpanSize(position: Int): Int {
                    return when (messages.size) {
                        // how to use this
                    }
                }
            }

xml for my image:

<com.google.android.material.imageview.ShapeableImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:shapeAppearance="@style/ShapeAppearanceOverlay.ChatPhoto"
        tools:ignore="ContentDescription" />

I'm making a chat app where the user can send photos. There may be 3 cases:

  1. When there is only one photo, the picture takes up the entire width and height

  2. When there are two pictures, then everything is divided into two parts (right and left)

  3. When there are three pictures, the first photo remains on the left as in the second case, and the remaining two are divided by the right container, which in turn is divided into two equal parts:

Example: enter image description here

How can i make it?

0

There are 0 best solutions below