GridLayoutManager定制

我想知道是否有办法,我可以定制的Android gridlayoutmanager有水平布局这样的草图: 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);

}}

任何帮助将不胜感激 感谢

回答:

我不认为你需要的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);

以上是 GridLayoutManager定制 的全部内容, 来源链接: utcz.com/qa/266956.html

回到顶部