Android Tips精选案例android系统控件

关于Google新的适配方式---FlexboxLayout

2017-05-15  本文已影响239人  T9的第三个三角

前言

工欲善其事必先利其器,学习FlexboxLayout之前,先看看它是用来干嘛的,都有哪些特性,了解之后,再来利用它。先放上项目地址--flexbox-layout的GitHub地址


正文

dependencies {
    compile 'com.google.android:flexbox:0.2.6'
}

开发测试版本 --包含了Recyclerview的集成

dependencies {
    compile 'com.google.android:flexbox:0.3.0-alpha3'
}

根据个人需求,选择合适版本

  
    <com.google.android.flexbox.FlexboxLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:alignItems="flex_start">

        <TextView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@color/colorAccent" />

        <TextView
            android:layout_width="100dp"
            android:layout_height="150dp"
            android:background="@color/blue" />

        <TextView
            android:layout_width="100dp"
            android:layout_height="180dp"
            android:background="@color/little_pink_primary" />

        <TextView
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:background="@color/black" />

        <TextView
            android:layout_width="120dp"
            android:layout_height="100dp"
            android:background="@color/orange" />

        <TextView
            android:layout_width="100dp"
            android:layout_height="80dp"
            android:background="@color/side" />

        <TextView
            android:layout_width="80dp"
            android:layout_height="200dp"
            android:background="@color/reset_check" />
    </com.google.android.flexbox.FlexboxLayout>
布局.png

可以看到类似LinearLayout,子元素是依次排列,唯一设置了属性就是app:alignItems="flex_start",那么FlexboxLayout都有哪些属性,每个属性的作用,需要我们一点点梳理,具体分为两个方面,一方面是FlexboxLayout的属性,另一方面是FlexboxLayout子元素的属性

FlexboxLayout属性

通过四张图的对比,是明显看出来各个属性的作用的

row row_reverse column column_reverse flex_start flex_end Paste_Image.png

根据图能很明显看出baseline的作用

baseline wrap wrap_reverse flex_end center space_around space-between flex_end center

FlexboxLayout子元素属性

第三个元素出现在第一个的位置 layout_flexBasisPercent

上面讲到FlexboxLayout有两个版本,内部测试版,添加了与Recyclerview的结合。

上一篇 下一篇

猜你喜欢

热点阅读