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
kotlin 复制代码
api("io.github.hellogoogle2000:android-flowlayout:1.0.3")
2. Apply in Xml Layout
xml 复制代码
<?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>
3. Convert View from Data

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

kotlin 复制代码
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
}

Preview



相关推荐
alexhilton9 小时前
Android XR 开发入门完全指南
android·kotlin·android jetpack
2501_9159090613 小时前
全面解析iOS应用上架到App Store的完整流程与关键注意事项
android·macos·ios·小程序·uni-app·cocoa·iphone
淡淡的香烟15 小时前
AndroidAI使用心得
android
chjif16 小时前
Android 设备管控开发实战:无障碍如何准确识别当前前台 App?
android
chjif16 小时前
Android 设备管控开发实战:企业受控终端的 DNS 域名策略实现
android·华为·harmonyos
c2385618 小时前
MySQL 基础用法(下):查询进阶与核心特性
android·c语言·c++·mysql
math_hongfan18 小时前
鸿蒙Agent高级技能自定义开发:自定义意图服务/能力注册/Agent技能编排/服务插件开发实战
android·学习·华为·harmonyos·鸿蒙
2501_9151063219 小时前
iOS 证书类型及作用说明 账号证书与签名配置的完整解读
android·ios·小程序·https·uni-app·iphone·webview
九皇叔叔19 小时前
RHEL9 安装 MySQL 8.4.11.LTS 版本
android·mysql·adb
海兰20 小时前
【数据库】tdsql(MySQL )的事务隔离级别
android·数据库·mysql