我有一组照片,我用它RecyclerView来显示它们.我希望在我的RecyclerViewspan 2列和2行中有第一个元素:

我知道我可以跨越2列setSpanSizeLookup:
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (position == 0) {
return 2;
} else {
return 1;
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是我怎么能让第一个项目跨越2行呢?
我尝试将第一个项目的高度设置为不同,通过膨胀不同的布局,其他布局的高度是其他布局的两倍,但这导致与第一个项目在同一行上的每个项目也被拉伸到该高度:
@Override
public ProfilePicViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView;
if (viewType == TYPE_MAIN_PHOTO) {
itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view_main_profile_photo, parent, false);
} else {
itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view_profile_photo, parent, false);
}
return new ProfilePicViewHolder(itemView);
}
Run Code Online (Sandbox Code Playgroud) 我想要一个RecyclerView.LayoutManager允许我为不同的行指定不同的跨度计数作为重复模式.例如2,3有10个项目看起来像这样:
-------------
| | |
| | |
-------------
| | | |
| | | |
-------------
| | |
| | |
-------------
| | | |
| | | |
-------------
Run Code Online (Sandbox Code Playgroud)
我能想到的方法与破解这个GridLayoutManager和SpanSizeLookup,但已经有人想出了一个更清洁的方式做到这一点?