Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

flaringapp/ConstraintFlowAdapter

Repository files navigation

ConstraintFlowAdapter

Implementation

implementation 'com.github.flaringapp:ConstraintFlowAdapter:1.0'

Sample app

Sample usage

class DemoConstraintFlowAdapter(
    private val items: List<ConstraintFlowItem>
): BaseConstraintFlowAdapter() {

    override fun initViews() {
        items.forEach {
            addView(createView(it))
        }
    }

    private fun createView(item: ConstraintFlowItem): View {
        val view = inflateView(R.layout.view_flow_item) as TextView
        view.id = View.generateViewId()
        view.text = item.text
        return view
    }
}

val adapter = DemoConstraintFlowAdapter(items)

Also you need to init adapter with your layout reference

adapter.init(flowLayout, flow.id)

Or

adapter.init(flowLayout)

And adapter will search for flow widget automatically

Sample layout

<androidx.constraintlayout.widget.ConstraintLayout 
    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:id="@+id/flowLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context=".MainActivity">

    <androidx.constraintlayout.helper.widget.Flow
        android:id="@+id/flow"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:flow_wrapMode="chain"
        app:flow_horizontalGap="8dp"
        app:flow_verticalGap="8dp"
        app:flow_horizontalBias="0"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages