我想知道是否有办法在android中自定义gridlayoutmanager,使其具有如下所示的水平布局:

我尝试了一些布局管理器,这是我在Github中找到的,但是它们没有帮助我实现这种布局管理器。
就像这样:
public class CustomLayoutManager extends StaggeredGridLayoutManager {
public CustomLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public CustomLayoutManager(int spanCount, int orientation) {
super(spanCount, orientation);
}
@Override
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
super.onMeasure(recycler, state, widthSpec, heightSpec);
}
@Override
public void setSpanCount(int spanCount) {
super.setSpanCount(spanCount);
}}如有任何帮助,将不胜感激。
发布于 2017-09-27 10:49:11
我不认为你需要CustomLayoutManager。这样做对你的RecyclerView
GridLayoutManager layoutManager = new GridLayoutManager(itemView.getContext(), 2, GridLayoutManager.HORIZONTAL, false);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return position == 0 ? 2 : 1;//put your condition here
}
});
recyclerView.setLayoutManager(layoutManager);https://stackoverflow.com/questions/46444900
复制相似问题