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);
+1
谢谢,它工作得很好 – destrat18
您可以在适配器中使用多种类型的布局。 –
我无法更改适配器设置。它是在Android电视环境 – destrat18
如果我的答案帮助你,请将其标记为已接受。 :) –