Detailed explanation of the use of recyclerview instead of listview (I)

Recyclerview is a new widget in android-support-v7-21, and a cardview will be introduced next time. Official introduction recyclerview is an upgraded version of listview, which is more advanced and flexible. Let's write a simple example to see how advanced and flexible it is.

build. Gradle configuration

start

The first is to use recyclerview in the layout file

In activity

The first feature of recyclerview is that it abstracts the layout into a layoutmanager. Recyclerview is not responsible for the layout of sub views. We can customize the layoutmanager to achieve different layout effects. At present, only linearlayoutmanager is provided. The linearlayoutmanager can specify the direction, which is vertical by default, and can specify the horizontal, so it is easy to implement the horizontal listview.

Next, let's see how the adapter is implemented

Another feature of recyclerview is that it standardizes the viewholder. The adapter is written for the viewholder instead of the view. The reuse logic is encapsulated and easier to write.

The above is what Xiaobian introduced to you. It will replace the use of listview's recyclerview (I). I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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