相关疑难解决方法(0)

具有不同单元格宽度的RecyclerView Grid的LayoutManager

StaggeredGridLayoutManager似乎不允许自定义单元格宽度或跨越多个列(垂直方向除外)以进行垂直方向.

在此输入图像描述

LayoutManager如上所示组织细胞的优选方法是什么?

PS我只是想知道如何自定义单元格宽度而不是高度StaggeredGridLayoutManager.我知道高度可以按照此示例中的实现进行定制.

public class VerticalStaggeredGridFragment extends RecyclerFragment {

    public static VerticalStaggeredGridFragment newInstance() {
        VerticalStaggeredGridFragment fragment = new VerticalStaggeredGridFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected RecyclerView.LayoutManager getLayoutManager() {
        return new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    }

    @Override
    protected RecyclerView.ItemDecoration getItemDecoration() {
        return new InsetDecoration(getActivity());
    }

    @Override
    protected int getDefaultItemCount() {
        return 100;
    }

    @Override
    protected SimpleAdapter getAdapter() {
        return new SimpleStaggeredAdapter();
    }
}
Run Code Online (Sandbox Code Playgroud)

适配器

public class SimpleStaggeredAdapter …
Run Code Online (Sandbox Code Playgroud)

android gridview android-recyclerview

25
推荐指数
3
解决办法
2万
查看次数

标签 统计

android ×1

android-recyclerview ×1

gridview ×1