RecyclerView实现流式布局
在项目中导入以下依赖:
dependencies { implementation 'com.google.android.flexbox:flexbox:3.0.0'
垂直排列:
RecyclerView recyclerView = (RecyclerView) context.findViewById(R.id.recyclerview); FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(context); layoutManager.setFlexDirection(FlexDirection.COLUMN); layoutManager.setJustifyContent(JustifyContent.FLEX_END); recyclerView.setLayoutManager(layoutManager);
默认是流式布局:
RecyclerView recyclerView = (RecyclerView) context.findViewById(R.id.recyclerview); FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(context); recyclerView.setLayoutManager(layoutManager);
更加详细的说明可以看github: