Android之RecyclerView:LayoutManager(线性布局管理器)

在RecyclerView中,我们可以通过LayoutManager控制其布局的显示方式,实现横向ListView、GridView、瀑布流等常见效果。

RecyclerView.LayoutManager是一个抽象类,其直接的实现类有LinearLayoutManager、StaggeredGridLayoutManager,而LinearLayoutManager也有一个子类GridLayoutManager.

1)通过LinearLayoutManager:我们可以实现横向、纵向的列表效果
2)通过GridLayoutManager:我们可以实现像GridView一样的网格布局
3)通过StaggeredGridLayoutManager:我们可以实现瀑布流的效果

有3个构造方法:

LinearLayoutManager(Context context) 

LinearLayoutManager(Context context,int orientation,boolean reverseLayout)

LinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr,int defStyleRes)

第一个构造方法内部调用了第二个构造方法

第二个构造方法参数的含义:

  • Context context :上下文,初始化时,构造方法内部加载资源用
  • int orientation :方向,垂直和水平,默认为垂直
  • boolean reverseLayout:是否倒序,设置为True,从最后一个item开始,倒序加载。此时,RecyclerView第一个item是添加进Adapter中的最后一个,最后一个item是第一个加进Adapter的数据,RecyclerView会自动滑到末尾
发布了34 篇原创文章 · 获赞 5 · 访问量 7475

猜你喜欢

转载自blog.csdn.net/qq_39438055/article/details/104161468
今日推荐