Android imitation meituan Taobao realizes multi-level drop-down menu function

We can see the drop-down secondary list menu in commonly used e-commerce or tourism apps, such as meituan, mobile Taobao, etc. See the figure for details:

The above two pictures are a display of a secondary list menu of meituan. I believe many people want to develop a function like it and put it into their own app. OK, let's start and solve it.

1. Structural analysis

First, we give the build required for this drop-down menu. We use wireframe to analyze.

1) As shown in the above figure, the outermost is an activity, and the top contains a view container. This container is mainly used to load togglebutton to realize the line of "food, the whole city, manage me recently, swipe" in meituan. One click on this line will pop up the corresponding menu.

2) How is the drop-down menu implemented?, Here we use popupwindow to realize this pop-up window. Then we define our next list item in the pop-up window. Whether it is a single column or a secondary menu is determined by the pop-up window.

3) Different menus need one or two levels, which can be changed according to my needs. We add a custom leftview, or middleview, rightview on popupwindow. It is mainly a toggle button. If you pop up a window, you can customize a window.

4) The listview is embedded in the view to form a list item.

OK, that's all for analysis. Next, let's explain the implementation step by step.

2. Project structure

The project structure of the project is shown in the figure:

1) Adapter。 Adapter, which mainly provides data adaptation for listview.

2)MainActivity。 Main activity page.

3)ExpandTabView。 The core class of this project, which contains the togglebutton container and popupwindow, is the core class for controlling pop-up windows.

4)ViewLeft,ViewMiddle,ViewRight。 Is to pop up the nested classes to implement different list menus.

3.MainActivity

Carries all elements. It's better to look at the code than the text.

4 .ExpandTabView

The most important thing is how to pop up or collapse these popupwindows when we click these toggle buttons.

5.ViewLeft

One example, the other two are not listed

6. Renderings

The above is the example code of Android imitation meituan Taobao to realize multi-level drop-down menu function and multiple items. I hope it will help 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
分享
二维码
< <上一篇
下一篇>>