我有一个嵌套列表,如A {a1,a2,a3 ... aN},B {B1,BM},...... O {O1,o2,... OP}这个。该列表具有随机数量的成员。每个成员也列出随机成员。这将显示如下图像。如您所见,外部单元的宽度和高度不固定。我想如果我使用嵌套的recyclerview可能是可能的。它有点像StaggeredGridLayoutManager。但据我所知,StaggeredGridLayoutManager应该有一个宽度或高度应该是固定的。有什么建议如何实现这种UI设计? This is what I want to display
This is what displayes when I use StaggeredGridLayoutManager
这是外部列表适配器 / ********** class GroupAdapter扩展了RecyclerView.Adapter {
@Override
public GroupHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_group, null);
GroupHolder ih = new GroupHolder(v);
return ih;
}
@Override
public void onBindViewHolder(GroupHolder holder, int position) {
if(mGroups!=null && mGroups.size()>position) {
GroupObject group = mGroups.get(position);
ArrayList<CandidateObject> cans = group.getCandidates();
CandidateAdapter adapter = new CandidateAdapter(cans);
CustomLinearLayoutManager mLinearManager = new CustomLinearLayoutManager(MainActivity.this);
mLinearManager.setAutoMeasureEnabled(true);
holder.rvCandis.setLayoutManager(mLinearManager);
holder.tvTitle.setText(group.getName());
holder.rvCandis.setAdapter(adapter);
}
}
@Override
public int getItemCount() {
return mGroups.size();
}
}
private static class GroupHolder extends RecyclerView.ViewHolder {
private TextView tvTitle;
private RecyclerView rvCandis;
public int index;
private GroupHolder(View v) {
super(v);
this.tvTitle = (TextView) v.findViewById(R.id.tv_partyname);
this.rvCandis = (RecyclerView) v.findViewById(R.id.rvCandi);
}
}
这是内部列表适配器 class CandidateAdapter扩展了RecyclerView.Adapter { ArrayList candis;
CandidateAdapter(ArrayList<CandidateObject> candis){
this.candis = candis;
}
@Override
public CandidateHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_candidate, null);
CandidateHolder ih = new CandidateHolder(v);
return ih;
}
@Override
public void onBindViewHolder(CandidateHolder holder, int position) {
if(candis!=null && candis.size()>position) {
CandidateObject c = candis.get(position);
holder.tvName.setText(c.getName());
}
}
@Override
public int getItemCount() {
return candis.size();
}
}
private static class CandidateHolder extends RecyclerView.ViewHolder {
private ImageView ivThumb;
private TextView tvName;
public int index;
private CandidateHolder(View v) {
super(v);
this.tvName = (TextView) v.findViewById(R.id.tv_name);
this.ivThumb = (ImageView) v.findViewById(R.id.ivNaver);
}
}
StaggeredGridLayoutManager是这样的。
setContentView(R.layout.activity_main);
StaggeredGridLayoutManager mLayManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
mRvVote = (RecyclerView) findViewById(R.id.rvVote);
mRvVote.setLayoutManager(mLayManager);