Android dynamic load layout

We always use listview, but sometimes we can't set some components when there are many contents in the adapter. For example:

You can see such a layout in Jingdong's story. It can be said that I have seen a lot of content at present. Each item of it includes avatar, name, classification, content, picture, like, comment, share and favorite avatar. After analyzing the layout, it is not difficult to find that except for the avatar, the rest are well implemented.

So now let's focus on how to realize this part of the avatar?

The first scheme: we can use GridView to implement it. The usage of GridView and listview is the same, commonly known as Jiugong grid arrangement. Then we can arrange nine pictures in a row of GridView to display these avatars, but the listview nested with GridView has a little trouble. We made one by ourselves, which is not easy to use, Anyone who wants to nest listview and GridView can privacy me.

The second scheme is the dynamic loading layout mentioned in this article:

Very simply, we define a linear layout in listview to store these avatars. Let's take a look at the layout first:

The LinearLayout above is for these avatars. I won't talk about others. Let's see how to add these avatars to our adapter

We first define a layoutparams, set some properties of the avatar image, including size, margins and scaletype, and then set it to our ImageView. Finally, holder.llreplyicons.addview (roundedimageview); Add sub layout is OK. JD has fixed the number of avatars, and what I wrote is to add avatars according to the width of the mobile phone screen:

Count is the avatar that can be added. When I in the view is equal to our count, we can display it with the last ellipsis picture. Before, someone in the group asked me how to click the avatar to jump to the personal home page. After thinking about it, can I use the coordinates touched by the mobile phone to calculate the coordinates between the first avatars? I think it's more troublesome. When adding sub layout avatars, we can set click events for this sub layout. Take a look at the code:

This code includes all the parameters, some of which are returned by the server and are real data. So you can click the avatar to jump. Finally, let's see if the interface I implemented is the same as JD's?

How about it? Is it almost the same?

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