Android news interface simulates the application of listview and viewpager

Simulate the interface of news app

1) Write layout before writing listview:

There are two layouts of items:

The first is a single picture, and the second is three pictures.

For the head layout added in listview, use viewpager to realize the sliding effect:

Finally, the layout of listview;

2) The data to be displayed in the listview is set here without network request.

Picture resources can be added freely

3) Custom adapter inherits baseadapter:

4) Because the head layout is implemented using viewpager, you need to add a custom adapter to inherit pageradapter:

Note how to achieve the loop effect when the viewpager slides - that is, set a very large boundary to display the loop.

5) You need a container to store the data to be displayed. Here you encapsulate a data class

6) Finally, configure adapters for listview and viewpager in mainactivity (at the same time, the text changes synchronously with the sliding of viewpager)

The above is the simulation example of the news interface. If you need it, you can have a look. Thank you for your support for this site!

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