FlexboxLayoutManager 用法

flexWrap
默認情況下 Flex 跟 LinearLayout 一樣,都是不帶換行排列的,但是flexWrap屬性可以支持換行排列。這個也比 LinearLayout 吊啊有三個值:

nowrap :不換行

wrap:按正常方向換行

wrap-reverse:按反方向換行

justifyContent
  justifyContent屬性定義了項目在主軸上的對齊方式。

flex-start(默認值):左對齊

flex-end:右對齊

center: 居中

space-between:兩端對齊,項目之間的間隔都相等。

space-around:每個項目兩側的間隔相等。所以,項目之間的間隔比項目與邊框的間隔大一倍。

alignItems
  alignItems屬性定義項目在副軸軸上如何對齊。

flex-start:交叉軸的起點對齊。

flex-end:交叉軸的終點對齊。

center:交叉軸的中點對齊。

baseline: 項目的第一行文字的基線對齊。

stretch(默認值):如果項目未設置高度或設爲auto,將佔滿整個容器的高度。

FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(mContext);
        //flexDirection 屬性決定主軸的方向(即項目的排列方向)。類似 LinearLayout 的 vertical 和 horizontal。
        flexboxLayoutManager.setFlexDirection(FlexDirection.COLUMN);//主軸爲水平方向,起點在左端。
        //flexWrap 默認情況下 Flex 跟 LinearLayout 一樣,都是不帶換行排列的,但是flexWrap屬性可以支持換行排列。
        flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP);//按正常方向換行
        //justifyContent 屬性定義了項目在主軸上的對齊方式。
        flexboxLayoutManager.setJustifyContent(JustifyContent.FLEX_START);//交叉軸的起點對齊。
        holder.mRlPromise.setLayoutManager(flexboxLayoutManager);
        NormalDividerItemDecoration normalDividerItemDecoration = new NormalDividerItemDecoration(mContext, NormalDividerItemDecoration.HORIZONTAL);
        holder.mRlPromise.addItemDecoration(normalDividerItemDecoration);
        holder.mRlPromise.setNestedScrollingEnabled(false);
        holder.mRlPromise.setAdapter(mPromiseTagAdapter);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章