GridView控件与行不同的列宽 [英] GridView with different column width in rows
问题描述
我有一个GridView中,我需要显示的图像。我已经申请以下逻辑:
I have a GridView in which I need to show images. I have applied below logic:
If 1 Photo : 1 row and 1 col and full width image.
If 2 Photos : 1 row and 2 cols with equal width of both images (half of screen width)
If 3 photos: 2 rows. 1st row will be having 1 col (1 image with full width)
and 2nd row will be having 2 images with equal width (half of screen width)
If 4 or more photos : width will be half for each column.
我对其余病例管理,唯一的问题是,为案件3时设置我有3张照片。
我想1全幅照片2行2 ANS等于半宽的照片在第二排,但我的code给我2第一排半宽度相等的照片,并在第二排1个半宽的照片。
I have managed for the rest cases, the only problem is to set for case 3 when I am having 3 photos. I want 1 full width photo in 2 row ans 2 equal half width photos in 2nd row but my code giving me 2 half equal width photos in 1st row and 1 half width photo in 2nd row.
我需要使用的GridView只,请告诉我,这可能是可以使用的GridView。我已经问过这个问题,但没有得到任何回应。
请帮助我,如果你这里有什么想法。
I need to use Gridview only, please tell me if this can be possible using Gridview. I have already asked this question but didn't get any response. Please help me if you have any idea here.
感谢您这么多。
我想有以下布局:
推荐答案
请参见下面
我已经创建了演示和做工精细。
I have created demo and working fine
rv = (RecyclerView) findViewById(R.id.rv);
final MyAdapter adapter = new MyAdapter();
rv.setAdapter(adapter);
GridLayoutManager mLayoutManager = new GridLayoutManager(this, 2);
rv.setLayoutManager(mLayoutManager);
mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (adapter.getItemCount() == 1) {
return 2;
} else if (adapter.getItemCount() == 2) {
return 1;
} else if (adapter.getItemCount() == 3) {
if (position == 0) {
return 2;
} else {
return 1;
}
} else {
return 1;
}
}
});
这篇关于GridView控件与行不同的列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!