【问题标题】:GridLayoutManager CustomizationGridLayoutManager 自定义
【发布时间】:2017-09-27 09:58:15
【问题描述】:

我想知道是否有办法让我在 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);
}}

任何帮助将不胜感激 谢谢

【问题讨论】:

  • 您可以在适配器中使用多种类型的布局。
  • 我无权更改适配器设置。它在安卓电视环境中
  • 如果我的回答对您有帮助,请将其标记为已接受。 :)
  • 只是需要时间检查一下 :) 再次感谢

标签: android layout-manager gridlayoutmanager staggeredgridlayout


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-14
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多