我需要创建一个类似于下面附带的XML布局。从服务器URL获取图像和类别名称。我编写了一个粗略的XML代码来获取详细信息。有人可以建议我在XML中使用什么来获得类似于设计的模拟器输出?谢谢!!
设计
这是现在的模拟器输出:
答案 0 :(得分:0)
将此gridLayoutManager
用于recyclerView
。
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 3);
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (position == 12) { // totalRowCount : How many item you want to show
return 3; // the item in position now takes up 3 spans
}
return 1;
}
});
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setHasFixedSize(true);
希望这会有所帮助。
答案 1 :(得分:0)
尝试这个。
ArrayList<Model> modellist=database.getData();
if(modellist.size()<=3)
{
LinearLayoutManager layoutManager= new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false);
recycieviewafirst.setLayoutManager(layoutManager);
YourAdapter adapter = new YourAdapter(this,modellist);
recycieviewafirst.setHasFixedSize(true);
}
else
{
int remaningRecode=modellist.size()%3;
if(remaningRecode==0)
{
GridLayoutManager manager = new GridLayoutManager(this, 3);
recycieviewfirst.setLayoutManager(manager);
YourAdapter adapter = new YourAdapter(this,modellist);
recycieviewfirst.setHasFixedSize(true);
}
else {
ArrayList<Model> lastRecodeArray = new ArrayList<>();
int i=modellist.size()-1;
Model model;
switch (remaningRecode)
{
case 1:
model = modellist.get(i);
lastRecodeArray.add(updateGSArtist);
modellist.remove(i);
break;
case 2:
model = modellist.get(i);
lastRecodeArray.add(model);
modellist.remove(i);
model = modellist.get(i-1);
lastRecodeArray.add(model);
modellist.remove(i-1);
break;
}
GridLayoutManager manager = new GridLayoutManager(this, 3);
recycieviewfirst.setLayoutManager(manager);
adapter =new YourAdapter(this,modellist);
recycieviewfirst.setHasFixedSize(true);
LinearLayoutManager layoutManager= new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false);
recycieviewartistsecond.setLayoutManager(layoutManager);
YourAdapter adaptersecond=new YourAdapter(this,lastRecodeArray);
recycieviewsecond.setAdapter(adaptersecond);
recycieviewsecond.setHasFixedSize(true);
}
}
recycieviewfirst.setAdapter(adapter);