Android implementation slide sidebar

In Android application development, the sliding sidebar is often used. Today, I also tried to carry out a simple practice. Although the function is not very powerful, it can be retained for future development and use, and simple modifications can be made when necessary. The idea of implementing a sliding sidebar is also very simple:

1. Rewrite a slidingmenu class to inherit the ViewGroup. In case of critical illness, the ViewGroup adds two sub layouts, which are menu and main interface display respectively;

2. In order to get a sliding effect, select scroller to help us realize it, and cooperate with the computescroll method under ViewGroup to update the interface;

3. Use a Boolean to record whether the menu is open. Sliding to the right when the menu is open will not respond, and sliding to the left when the menu is closed will not respond;

4. In order to get a good interaction, we can define a proportion for the distance between interface sliding and finger movement. For example, for each touch event, the distance of interface movement is only half of that of finger movement;

The following are two renderings. The interface has little layout. Let's make do with it

Implementation code of slidingmenu:

Call in mainactivity

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