How to realize the function of self-defined View deployment menu by Android
This article introduces the "Android how to achieve custom View expansion menu function" related knowledge, in the actual case of the operation process, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
Effect picture
Train of thought
1. The parent View of the lower corner Button adds a FrameLayout, that is, the transparent gray part of the full screen.
Set to invisible when the menu does not pop up.
Set the FrameLayout click event and retract the menu when clicked.
Corresponding to init ()
Add menu buttons to 2.rameLayout, the three pop-up buttons.
Set to invisible when the menu does not pop up.
Corresponding to addElement () and freshElement ()
3. The button in the lower right corner, rotate the icon (or not).
Corresponding to setRotateAnimation ()
4. Sex animation changes the transparency of fragment from 0 to 1
Corresponding to changeBackgroudStatus ()
5. The single button is made visible and pops around
Corresponding to setTranslation ()
Click on me to check the source code
How to use it:
In the XML file, the parent class is FloatingActionButton:
In Activity:
UnfoldButton f = (UnfoldButton) findViewById (R.id.unfoldButton); f.addElement (R.drawable.bestjay, new View.OnClickListener () {@ Override public void onClick (View v) {/ / Click events} of the menu written here}); f.addElement (R.drawable.bestjayjay null); / / ditto f.addElement (R.drawable.bestjayjay null); / / Ibid f.setmRotatable (true) / / sets whether the icon is rotated by default to true f.setmScale (1); / / sets the scale of the pop-up scale 1 to the non-scaling range: 0-1 f.setLength (250); / / sets the pop-up distance
After the pop-up menu, the background color is up to you. You need to declare a color in colors.xml:
# 9b414141
Name must be "background"
This is the end of the content of "how to implement the custom View deployment menu function by Android". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!