Use of recyclerview HelloWorld

In other words, recyclerview has been on the market for a long time and is widely used in many applications. It also has a good reputation in the whole developer circle. That shows that recyclerview has many advantages over listview, GridView and other controls, such as data binding, item view creation, view recycling and reuse.

Recyclerview is a new control released with Android 5.0. It is a list container. Google intends to replace the old listview and GridView with a new recyclerview. Its flexibility and performance are better than listview. Next, learn about various usage methods of recyclerview through a series of articles. This article introduces its preliminary use, recyclerview's "helloword".

The difference between recyclerview and traditional listview:

1: Viewholder mode: traditional listview can improve the performance of list scrolling through viewholder, but this is not necessary because listview does not have a strict standard design mode, but when using recyclerview, the adapter must implement at least one viewholder because it has a strict viewholder design mode.

2: For display effect, listview can only realize vertical scrolling list view. On the contrary, recyclerview can be set by setting recyclerview Layoutmanager to customize different styles of views, such as horizontal scrolling list or irregular waterfall flow list.

3: For list item animation, no method or interface is provided in listview to facilitate developers to realize the addition and deletion animation of items. Recyclerview can be set through the recyclerview Itemanimator to animate items.

This article uses the following small demo to understand the initial use of recyclerview

*The copyright of the picture material belongs to smartisan com

1: Dependency Library (this article takes Android studio as the development tool)

Gradle configures compile 'com android. support:recyclerview-v7:23.1. 1'

2: Create layout, similar to listview, and add recyclerview to the layout

3: Create recyclerview item layout

A control called cardview is used here, which inherits from FrameLayout. It is a card view container provided by Google. It can easily display the card layout with shadows and rounded corners, like this

Like recyclerview, cardview also needs to be imported before use

compile 'com. android. support:cardview-v7:23.1. 1'

4: Then create the recyclerview adapter

5:RecycleViewActivity. java

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>