Android imitation Jingdong, pinduoduo commodity classification page example code

Recently, I received a project to write a commodity classification page based on JD. However, I need to slide the sub classification on the right, and the main classification on the left is also changed. I wrote a demo, which can be taken by students who need it.

Put a look after writing:

The idea of writing this requirement is also very clear. First, there must be a listview on the left and a listview on the right. The two listviews should achieve a linkage effect. The listview on the right can be nested with another GridView. As shown in the figure below.

Therefore, the data structure we need is determined. It should be an array set of arrays, that is, there are sub Classified Goods under the skin care category, similar to this:

OK, once the data and UI structure are determined, you can write code

1. First determine the main structure, that is, two listviews

Don't worry about the Hello world above. It just wants to make a ceiling effect

2. Render the left data and the right data separately

2.1 render the data on the left, i.e.:

It's very simple. I won't repeat it. A complete code link will be attached at the bottom

2.2 rendering right side data

In the homeadapter, you also need to nest the GridView, as follows:

Two points need to be explained here. First, because listview nested GridView will have a well-known problem of calculating the height, it is necessary to re measure the height here, that is, rewrite the GridView; Second: the textview in the code is the name of the main title in each sub title, that is, it needs to be sucked at the top.

Above, the data can be rendered, and now it is the problem of linkage

3. Let the two parts of data move

3.1 master data linkage sub data

You only need to call the onItemClick () method of the master data, and the right data can be called by the setSelection () method in the replication method.

3.2 sub data linkage master data

Just process the data in onscroll and update the adapter of the master data. As shown in the code

4. Ceiling effect

There are several methods here that can achieve similar effects. In my side, there has always been one above. I add a type to all the sub data. When the type is different, replace the one above.

Finally, attach the GIT link direct link

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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