Android-defined controls: old Youku Three-level menu (renderings + Demo)

Source: Internet
Author: User

:


Production ideas:

1, the first analysis of this effect, in fact can be understood as the three-level menu divided into Level1,level2,level3,level1 is always displayed.

After clicking Level1, Level2 will appear, LEVEL3 will appear after clicking Level2, and clicking Level2,level3 and Level1,level2 will disappear after LEVEL3 appears.

Then disappears and appears we used an animated effect.

2, the animation effect is used to rotateanimation. Because we all use the same effect, then we just have to write a class, the effect can be achieved. If you use Rotateanimation. We will continue to reuse some code, so that the development efficiency will be lower.

3. The rotation of the rotateanimation into and out is a pit-because he rotates clockwise in the x-axis. You can look at the picture:


The general idea is this, and then there are some operations:

Code:

1, Myanimation class:

public class Myanimation{public static void Animationin (view view) {Animationin (view,0);} public static void Animationout (view view) {animationout (view,0);} public static void Animationin (View view,long delay) {rotateanimation animation = new Rotateanimation (,, View.getwi DTH ()/2, View.getheight ()); animation.setduration; Animation.setfillafter (true); Animation.setstartoffset ( delay); view.startanimation (animation);} public static void Animationout (View view,long delay) {rotateanimation animation = new Rotateanimation (0, View.getwid Th ()/2, View.getheight ()); animation.setduration (+); Animation.setfillafter (true); Animation.setstartoffset ( delay); view.startanimation (animation);}}

2, Mainactivity class:

public class Mainactivity extends Activity implements Onclicklistener{private Boolean islevel2showed,islevel3showed; Private Relativelayout level1,level2,level3;private ImageButton home,menu; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); isLevel2showed = false; islevel3showed = False;initlayout (); Initimagebutton ();} public void Initlayout () {level1 = (relativelayout) Findviewbyid (r.id.relate_level1); Level2 = (relativelayout) Findviewbyid (R.ID.RELATE_LEVEL2); level3 = (relativelayout) Findviewbyid (R.ID.RELATE_LEVEL3); Level2.setvisibility ( view.invisible); level3.setvisibility (view.invisible);} public void Initimagebutton () {home = (ImageButton) Level1.findviewbyid (r.id.home); menu = (ImageButton) Level2.findviewbyid (R.id.menu); Home.setonclicklistener (this); Menu.setonclicklistener (this);} @Overridepublic void OnClick (View v) {switch (V.getid ()) {case R.id.home:if (!islevel2showed) {islevel2showed = true; Myanimation.animationin (LEVEL2);} else if (!islevel3showed) {islevel2showed = false; Myanimation.animationout (LEVEL2);} else{islevel2showed = false;islevel3showed = false; Myanimation.animationout (LEVEL3); Myanimation.animationout (level2,500);} Break;case R.id.menu:if (!islevel3showed) {islevel3showed = true; Myanimation.animationin (LEVEL3);} else{islevel3showed = false; Myanimation.animationout (LEVEL3);} Break;}}}


Source code Download

Android-defined controls: old Youku Three-level menu (+ Demo)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.