问题描述
有人知道如何使用RecyclerView进行流布局吗?
Does anyone know how to do flow layout using RecyclerView?
如何动态更改跨度计数?
How to change span count dynamically?
推荐答案
以下是完整示例使用类似于列表 GitHubLibrary TagLayout
Here is the full exampleof using custom Library which acts like List GitHubLibrary TagLayout
- 示例代码:-
mFlowLayout.setAdapter(new TagAdapter<String>(mVals) { @Override public View getView(FlowLayout parent, int position, String s) { TextView tv = (TextView) mInflater.inflate(R.layout.tv, mFlowLayout, false); tv.setText(s); return tv; } });
mFlowLayout.setAdapter(new TagAdapter<String>(mVals) { @Override public View getView(FlowLayout parent, int position, String s) { TextView tv = (TextView) mInflater.inflate(R.layout.tv, mFlowLayout, false); tv.setText(s); return tv; } });
使用以下代码,您可以预先设置所需的选择:-
mAdapter.setSelectedList(1,3,5,7,8,9);
将显示如下结果:-
这篇关于有谁知道如何使用RecyclerView进行流布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!