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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章