How to create circle layout manager for recyclerview in android

Viewed 45

In my application I want create circle layoutmanager for RecyclerView such as below image.
Image sample :
enter image description here

I searched in Google and Youtube but not found any way.
How can I create this?

1 Answers

You can achieve it by adding an item decoration to recyclerview. Firstly, create ItemDecoration class

class ItemDecoration : RecyclerView.ItemDecoration() {

    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        outRect.set(-20, 0, 0, 0)
    }
}

when setup your recyclerview, don't forget to implement this method

recyclerView.addItemDecoration(ItemDecoration())

and this is item_view.xml layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="80dp"
    android:layout_height="80dp"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardElevation="20dp"
    app:cardCornerRadius="50dp">

    <ImageView
        android:id="@+id/ivListItem"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/image" />
</androidx.cardview.widget.CardView>

Have fun coding! :)

Related