Recyclerview uses a variety of item loading layouts

This article introduces Jie Shi how to use recyclerview to load multi item layouts. Loading multi item layouts means that each item of the list may load different layouts according to different requirements in the development process.

Now let's show you the demonstration effect picture:

*The copyright of image resources belongs to Facebook dribble

The core of recyclerview's implementation of loading different layouts is to load different layouts according to requirements in oncreateviewholder of adapter.

Specific implementation steps: (take Android studio as the development tool)

1: Gradle configuration build gradle

Here, cardview is also a new layout container, which was introduced in the previous article.

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

2: Create a layout activity for the list_ recyclerview. xml

Since multiple item layouts need to be loaded, we need to create two item layouts

3: Create layout of list item items (1) item1.xml

4: Create the layout of list item items (2) item2.xml

*The most important part is the adapter

5: Create recyclerview adapter, recyclerviewadapter java

OK, after the adapter is established, the last step is to perform relevant operations in the activity

6: The class file of the list page, recyclerviewactivity java

OK, in this way, the multi item layout of recyclerview can be loaded. I have introduced so many item loading layouts about the use of recyclerview. I hope it will be helpful to you!

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
分享
二维码
< <上一篇
下一篇>>