第三方开源库:流式布局:FlowLayout

来源:互联网 发布:ubuntu怎么安装wps 编辑:程序博客网 时间:2024/05/22 13:50

FlowLayout

github:https://github.com/nex3z/FlowLayout
使用的时候把子view添加到FlowLayout中。

flowLayout.addView(tv);

这里写图片描述

属性

属性 说明 app:childSpacing=”auto” 子布局的间隔 app:childSpacingForLastRow=”align” 最后一行子布局 app:rowSpacing=”8dp” 行间距 app:rtl=”true”

xml:

<com.nex3z.flowlayout.FlowLayout    android:id="@+id/flowLayout"    android:layout_width="match_parent"    android:layout_height="wrap_content"    app:childSpacing="auto"    app:childSpacingForLastRow="align"    app:rowSpacing="8dp"    app:rtl="true"/>

Java

flowLayout = (FlowLayout) findViewById(R.id.flowLayout);array = getResources().getStringArray(R.array.lorem_ipsum);for (int i = 0; i < array.length; i++) {    TextView tv = new TextView(this);    tv.setText(array[i]);    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,16);    tv.setPadding(30,10,30,10);    tv.setBackgroundResource(R.drawable.tv_bg_shape);    flowLayout.addView(tv);}
0 0