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);
}