本文介绍了如何实现水平网格布局管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用recyclerview实现水平gridlayoutmanager.固定行数.和水平滚动.这样...

How to implement horizontal gridlayoutmanager with recyclerview.Fixed row count. and horizontal scroll.Like this...

        gridLayoutManager = new GridLayoutManager(getContext(), 1, GridLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(gridLayoutManager);
    recyclerView.setHasFixedSize(true);

我尝试这样做.但这并没有在项目中显示任何内容.

I try do this. but this is not show anything in item.

推荐答案

  1. 安装RecyclerAdapter,ViewHolder.
  2. 实例化RecyclerAdapter,设置其适配器.
  3. 指定ROWSCOUNT(您的图片上有3行):GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), ROWSCOUNT, GridLayoutManager.HORIZONTAL, false);

  1. Implement RecyclerAdapter, ViewHolder.
  2. Instantiate RecyclerAdapter, set its' adapter.
  3. Specify ROWSCOUNT (there are 3 rows on your picture):GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), ROWSCOUNT, GridLayoutManager.HORIZONTAL, false);

设置布局管理器:recyclerView.setLayoutManager(gridLayoutManager);

Set layout manager: recyclerView.setLayoutManager(gridLayoutManager);

显示您的回收站视图setContentView(recyclerView);

Show your recycler view setContentView(recyclerView);

我已经为您准备了一个示例,请查看

这篇关于如何实现水平网格布局管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:37