RecyclerView介绍(一)----简单概述

来源:互联网 发布:php的进程是什么 编辑:程序博客网 时间:2024/05/18 02:45

最近时间有时间,正好研究研究RecyclerView 一看 才发现确实很强大 下面 就逐一介绍 最近的成果。先从API看起 对RecyclerView的介绍如下
A Recycler is responsible for managing scrapped or detached item views for reuse.
A “scrapped” view is a view that is still attached to its parent RecyclerView but that has been marked for removal or reuse.
Typical use of a Recycler by a RecyclerView.LayoutManager will be to obtain views for an adapter’s data set representing the data at a given position or item ID. If the view to be reused is considered “dirty” the adapter will be asked to rebind it. If not, the view can be quickly reused by the LayoutManager with no further work. Clean views that have not requested layout may be repositioned by a LayoutManager without remeasurement.
以上英文看不懂没关系 我简单说说我个人的理解 Recycler 顾名思义 回收者的意思 这也是RecyclerView的精髓所在 google之所以推出RecyclerView就是进一步对常用控件进行优化,而RecyclerView重点关注的是如何回收和复用View。就像上文说的,如果不是“dirty”的view那么 会通过LayoutManager快速的复用。
说到这 我们必须介绍一下LayoutManager了 我们先看一下官方的介绍:
A LayoutManager is responsible for measuring and positioning item views within a RecyclerView as well as determining the policy for when to recycle item views that are no longer visible to the user. By changing the LayoutManager a RecyclerView can be used to implement a standard vertically scrolling list, a uniform grid, staggered grids, horizontally scrolling collections and more. Several stock layout managers are provided for general use.
If the LayoutManager specifies a default constructor or one with the signature (Context, AttributeSet, int, int), RecyclerView will instantiate and set the LayoutManager when being inflated. Most used properties can be then obtained from getProperties(Context, AttributeSet, int, int). In case a LayoutManager specifies both constructors, the non-default constructor will take precedence.
我个人理解是这样的,LayoutManager暂且叫做布局管理器吧 ,布局管理器是负责测量和定位每一个子的view的,同时还有回收子view不再对用户可见的策略。而且还用来 用来这个布局管理器来控制RecyclerView的显示风格,比如我们常见的listview gridview 横向 竖向瀑布流等风格这个我会再之后的代码示例当中一一给出。
简单来说 需要记住两点:
1.RecyclerView 重点关注的是如何回收和复用View
2.通过LayoutManager来控制RecyclerView的显示风格
如果 我们在代码中有以下几种需求:
A.ListView的功能
B.GridView的功能
C.横向ListView
D.横向GridView
E.瀑布流
或者多种以上效果互相切换 则优先考虑用RecyclerView 而且代码简单只需要改变LayoutManager来实现
下面 我们通过代码逐一进行介绍。

0 0
原创粉丝点击