FlexboxLayout弹性盒子布局
说明
Flex是Flexible Box的缩写,意为「弹性布局」,在前端css样式中应用甚为广泛,之前做过React-Native和微信小程序,页面布局大 多使用flex弹性布局,可以在不同屏幕尺寸上提供一致的布局结构,可以简便、完整、响应式地实现各种页面布局,今天为大家打开Android移动端的flex布局大门--FlexboxLayout,在android中我们经常所见的标签、流式布局等都可以用FlexboxLayout来实现。
使用示例
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:android="http://schemas.android.com/apk/res/android"
xsi:noNamespaceSchemaLocation="layout.xsd"
android:background="#333333"
android:layout_height="match_parent"
android:layout_width="match_parent">
<FlexboxLayout android:layout_height="200dp"
android:layout_width="match_parent"
android:background="#888888"
android:flexDirection="row"
android:flexWrap="wrap">
<Button android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_order="1"
android:layout_flexGrow="20.0"
android:layout_flexShrink="20.0"
android:layout_alignSelf="auto"
android:layout_height="wrap_content"
android:text="1"/>
<Button android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="2"/>
<Button android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="3"/>
<Button android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="4"/>
<Button android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="5"/>
<Button android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="6"/>
</FlexboxLayout>
</ScrollView>