当前位置:   article > 正文

Android FlowLayout

Android FlowLayout

About this Project

An android auto-adaptive layout library

Core Ability

Auto wrap line when item reach parent end

Attributes

  • itemMarginX, padding between each column
  • itemMarginY, padding between each row
  • item margins will be ignored, you can use padding or wrapper view instead

Steps for Integration

1. Dependency
api("io.github.hellogoogle2000:android-flowlayout:1.0.3")
  • 1
2. Apply in Xml Layout
<?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="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <com.android.library.flowlayout.FlowLayout
        android:id="@+id/flowLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="20dp"
        app:itemMarginX="10dp"
        app:itemMarginY="5dp">

        <TextView
            android:layout_width="50dp"
            android:layout_height="30dp"
            android:background="#22FF0000"
            android:gravity="center"
            android:text="1"
            android:textSize="20dp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="80dp"
            android:layout_height="30dp"
            android:background="#22FF0000"
            android:gravity="center"
            android:text="2"
            android:textSize="20dp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="200dp"
            android:layout_height="30dp"
            android:background="#22FF0000"
            android:gravity="center"
            android:text="3"
            android:textSize="20dp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="190dp"
            android:layout_height="30dp"
            android:background="#22FF0000"
            android:gravity="center"
            android:text="4"
            android:textSize="20dp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="40dp"
            android:layout_height="30dp"
            android:background="#22FF0000"
            android:gravity="center"
            android:text="5"
            android:textSize="20dp"
            android:textStyle="bold" />
    </com.android.library.flowlayout.FlowLayout>
</LinearLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
3. Convert View from Data

you are also enabled to create view from a data set dynamically

val simulated = mutableListOf<String>().apply {
    for (i in 0 until 30)
        add(UUID.randomUUID().toString())
}
binding.flowLayout.applyViewAdapter({ Button(this) }, simulated) { view, data ->
    view.text = data
    view.setPadding(15, 15, 15, 15)
    val lp = view.layoutParams
    lp.width = ViewGroup.LayoutParams.WRAP_CONTENT
    lp.height = ViewGroup.LayoutParams.WRAP_CONTENT
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

Preview

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/841855
推荐阅读
相关标签
  

闽ICP备14008679号