RecyclerView基本使用

  • 时间:
  • 浏览:0

正所谓“学以致用”,验明否是 掌握了一门东西的最好法律办法是并能把这名 东西讲给别人听,别人还能听懂。

传送门

这里说明下有几个法律办法:

博客地址

前面铺垫了这么 多,接下来亲们就实际看看另另另一个 最简单的RecyclerView怎么能能撰写吧?

这三个组成次责依赖关系是Item->ViewHolder->Adapter->RecyclerView

这里让我截取官网上的两段文字来说明。

事先在展示列表时时不时全部都是在使用ListView。

因此本篇打算说下RecyclerView的基本使用,给亲们参考下。

Many apps need to display user-interface elements based on large data sets, or data that frequently changes. For example, a music app might need to display information about thousands of albums, but only a dozen of those albums might be on-screen at a time. If the app created UI widgets for each of those albums, the app would end up using a lot of memory and storage, potentially making the app slow and crash-prone. On the other hand, if the app created UI widgets each time a new album scrolled onto the screen and destroyed the widgets when it scrolled off, that would also cause the app to run slowly, since creating UI objects is a resource-intensive operation.

To address this common situation, the Android Support Library provides the RecyclerView suite of objects. RecyclerView and its associated classes and interfaces help you to design and implement a dynamic user interface that runs efficiently. You can use these classes as they are, or customize them to suit your specific needs.

这里使用了butterknife对TextView进行初始化。

因此然后接触到了RecyclerView事先,就喜欢上了RecyclerView。

唯一的区别大概可是我我适配器Adapter的不同而已。

原应 这里使用了butterknife,可是我创建的事先就初始化了。

心动不如行动,赶紧本人去敲下代码熟悉下呗~代码传送门

可是我基于此,本篇文章应运而生。

首先说明下RecyclerView的几大组成次责:

这么 ,另另另一个 简单的RecycleView就完成了。

好了,接下来然后亲们一步一步来实现另另另一个 展示文本的列表。

在使用RecyclerView的布局文件中加入下面代码:

简单的说RecyclerView在显示小量数据的事先能起到高效的作用。

A flexible view for providing a limited window into a large data set.

传送门

初始化RecyclerView并将其与适配器绑定。