About this menu should be seen in many player applications, directly on the first two, one is the demo, one is Youku mobile client.
Because there is no time to make their own icons, so the demo is used in the Youku mobile phone client icon.
First it can be seen that the menu interface is divided into three layers, so we use the Relativelayout layout to arrange the three-level menu background.
Second, in each layer of the menu, each icon is also relative to their own menu level has a fixed position, so each menu level also uses Relativelayout layout.
Now that the layout is analyzed clearly, you can start writing the layout file directly. It is important to note that each icon is positioned relative to each other to make the overall effect better.
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Tools:context =". Mainactivity "> <relativelayout android:id=" @+id/level1 "android:layout_width=" 100dip "Andro id:layout_height= "50dip" android:layout_alignparentbottom= "true" android:layout_centerhorizontal= "true" android:background= "@drawable/level1" > <imageview android:id= "@+id/icon_home" Andro Id:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:background= "@drawable/ic On_home "android:layout_centerinparent=" true "/> </RelativeLayout> <relativelayout and Roid:id= "@+id/level2" android:layout_width= "180dip" android:layout_height= "90dip" Android:layout_alig Nparentbottom= "true" android:layout_centerhorizontal= "true" android:background= "@drawable/level2" > <imageview androi D:id= "@+id/icon_search" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:background= "@drawable/icon_search" android:layout_alignparentbottom= "true" android:l ayout_margin= "10dip"/> <imageview android:id= "@+id/icon_menu" Android:layout_wi Dth= "Wrap_content" android:layout_height= "wrap_content" android:background= "@drawable/icon_menu" android:layout_margintop= "5dip" android:layout_centerhorizontal= "true"/> <imagevie W android:id= "@+id/icon_myyouku" android:layout_width= "Wrap_content" Android:layout_heig ht= "Wrap_content" android:background= "@drawable/icon_myyouku" android:layout_alignparentbottom= "true "Android:layOut_alignparentright= "true" android:layout_margin= "10dip"/> </RelativeLayout> <relati Velayout android:id= "@+id/level3" android:layout_width= "280dip" android:layout_height= "140dip" Android:layout_alignparentbottom= "true" android:layout_centerhorizontal= "true" android:background= "@drawabl E/level3 "> <imageview android:id=" @+id/channel1 "android:layout_width=" Wrap_c Ontent "android:layout_height=" wrap_content "android:background=" @drawable/channel1 "Android Oid:layout_alignparentbottom= "true" android:layout_marginleft= "10dip" android:layout_marginbottom= "1 0dip "/> <imageview android:id=" @+id/channel2 "android:layout_width=" Wrap_conte NT "android:layout_height=" Wrap_content "android:background=" @drawable/channel2 "Android: Layout_above= "@id/channeL1 "android:layout_alignleft=" @id/channel1 "android:layout_marginleft=" 18dip "Android:lay out_marginbottom= "6dip"/> <imageview android:id= "@+id/channel3" Android:layout_width= "W Rap_content "android:layout_height=" wrap_content "android:layout_above=" @+id/channel2 "an droid:layout_alignleft= "@id/channel2" android:background= "@drawable/channel3" Android:layout_margin left= "30dip" android:layout_marginbottom= "6dip"/> <imageview android:id= "@+id/ Channel4 "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "Androi d:background= "@drawable/channel4" android:layout_centerhorizontal= "true" android:layout_margintop= "5 Dip "/> <imageview android:id=" @+id/channel7 "android:layout_width=" Wrap_conten T "Android:layout_height= "Wrap_content" android:background= "@drawable/channel7" android:layout_alignparentbottom= "True" android:layout_alignparentright= "true" android:layout_marginright= "10dip" Android: layout_marginbottom= "10dip"/> <imageview android:id= "@+id/channel6" Android:la Yout_width= "Wrap_content" android:layout_height= "wrap_content" android:background= "@drawable/channel 6 "android:layout_above=" @id/channel7 "android:layout_alignright=" @id/channel7 "android:l ayout_marginright= "18dip" android:layout_marginbottom= "6dip"/> <imageview Andro Id:id= "@+id/channel5" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_above= "@+id/channel6" android:layout_alignright= "@id/channel6" Android:backgrou nd= "@drawable/channel5" android:layout_marginright= "30dip" android:layout_marginbottom= "6dip"/> </relative Layout></relativelayout>
Second, mainactivity loading layout file
First of all, the analysis can be drawn, each level of the menu disappears and the animation is similar, so you can create a tool class, to unify the animation effect of the code, here to establish Myutils.java
The overall animation effect is divided into, disappear and appear, so only the implementation of these two methods is good.
/** * Animated effects that appear
* @param view that requires animation effect
* @startOffset time to delay execution */public static void Startanimin (relativelayout view, int startoffset) {rotateanimation Animation = new Rotateanimation (2, View.getheight (), view.getwidth ()/Animation.setduration (); Set the run time Animation.setfillafter (true); The last state of Animation.setstartoffset (Startoffset) is maintained after the animation is executed. Set time View.startanimation (animation) for deferred execution;}
In the code, the Rotateanimation class is used to control the animation effect of the view.
What we need is a rotating animation effect, so we need to know that the default center is the upper left corner of the view, which needs to be set as the center of the view, i.e. (View.getwidth ()/2, View.getheight ())
By the same token, you only need to modify the rotation angle of the same animation effect to write the effect of vanishing animation.
/** * Allow the specified view delay to perform rotation away animation * @param view * @param i delay time */public static void Startanimout (relativelayout view, int startoff Set) {rotateanimation animation = new Rotateanimation (0, View.getwidth ()/2, View.getheight ()); Animation.setduration (+); Set the run time Animation.setfillafter (true); The last state Animation.setstartoffset (Startoffset) is maintained after the animation is executed, or the time view.startanimation (animation) is set for deferred execution;}
After the animation effect class is complete, you can return to the mainactivity to listen for the Click event of the button.
@Overridepublic void OnClick (View v) {switch (V.getid ()) {Case r.id.icon_menu://handles the Click event of the menu icon//If the third-level menu is display state, hide it if ( Islevel3show) {//Hide myutils.startanimout (level3,0);} else {//show myutils.startanimin (level3,0);} Islevel3show =!islevel3show;break;case r.id.icon_home://handles the Click event of the Home icon//If the level two menu is display state, then hide 2, Level 3 menu if (islevel2show) { Myutils.startanimout (level2,0); islevel2show = False;if (islevel3show) {myutils.startanimout (level3,200); Islevel3show = false;} } else {//If the level two menu is hidden, then the Level 2 menu Myutils.startanimin (level2,0) is displayed; islevel2show = true;} Break;default:break;}}
The last is to modify the menu button's events so that the menu can be pressed to hide or show the effect of all menus.
Four, the demo download