当前位置: 移动技术网 > 移动技术>移动开发>Android > 自定义流式布局FlowLayout

自定义流式布局FlowLayout

2020年07月08日  | 移动技术网移动技术  | 我要评论

FlowLayout

FlowLayout是自定义ViewGroup,实现了流式布局,自动换行的功能,并且可以控制最大行数,设置水平间距,垂直间距和子View垂直居中。
github地址
效果图:
在这里插入图片描述

使用方法:

在布局中声明,并设置自定义属性:

   <com.ayy.flowlayout.FlowLayout
        android:id="@+id/flow_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:horizontal_space="10dp" //水平间距
        app:vertical_space="10dp" //垂直间距
        app:max_line="3" //控制行数
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent">
        
    </com.ayy.flowlayout.FlowLayout    
        

直接在xml中包裹子View

    <com.ayy.flowlayout.FlowLayout
        android:id="@+id/flow_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:horizontal_space="10dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:max_line="3"
        app:vertical_space="10dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="哈哈" />
    </com.ayy.flowlayout.FlowLayout>

或者在代码中addView

TextView textView = new TextView(this);
flowLayout.addView(textView);

github地址

本文地址:https://blog.csdn.net/anyanyan07/article/details/107125642

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网