The realization of the Android property animation and the effect of smart menu

Source: Internet
Author: User

Some time ago, I learned to customize the view, basically can draw some more good-looking control, then today, I will learn the property animation. I also briefly looked at the concept of attribute animation, and then also looked at the effect of some basic concepts, such as animator, Objectanimator, interpolation and so on. For this reason I also deliberately wrote blog Android technology advanced elements--android attribute animation, but not a project to consolidate, also have been brooding, today can finally start to write this process, well, so much nonsense, the following start to see today's content, I was through the demo to understand the properties of animation. First look at your effect:

This is the effect of the expansion, because it is not a dynamic diagram, so do not see the full effect, I briefly describe, when the "+" in the middle, will be from the "+" smart pop-up three buttons, these three buttons appear in the process, but also with animation effect, the same, close is also so, the same, These three buttons are also registered with the Click event.

Next, we start coding because the menu is presented as a whole, so I'm going to implement this control as a viewgroup,

Create a new class with the name Mmenu, inherit from Relativelayout, and implement the interface of the Click event to see the variables we used at this time:

     ImageView Center,home,call,hyperlink;

     List<imageview> oviews;

      mflag=;

      Mhiddenviewmeasuredheight;

Not much, first of all, there are four picture controls, then a list set, for loading ImageView, the following one is used to distinguish between opening or closing the menu bar, and then one is the motion length of the animation.

The following starts the initialization operation:

    private void Initview {Layoutinflater (context) (

        r_layout, this)
        center= (ImageView) Findviewbyid (r)
        = (ImageView) Findviewbyid (R)
        home= (ImageView) Findviewbyid (R)
        hyperlink= (ImageView) Findviewbyid (R)

        //Place four ImageView in a collection for easy management
        oviews=new arraylist<imageview> ()
        oviews (center)
        oviews ()
        oviews (Home) oviews (this) [This] home
        (
        this) Hyperlink (this)
    }

This loads the layout file, then introduces the control, sets the Click event, and so on. Next in the Onsizechanged method to assign the size of the displacement, the code is as follows:

    
      (W,  H,  oldw,  oldh) {
        . onsizechanged (W, H, OLDW, OLDH);
        Mhiddenviewmeasuredheight = () (w*/);
        Anim (Mhiddenviewmeasuredheight,-mhiddenviewmeasuredheight, F, F, F, f);

    }

Here we start by setting the menu to close. The following starts with the main code and an action on the animation effect of the control, the following code:

      (Mhiddenviewmeasuredheightbegin, Mhiddenviewmeasuredheightyclose, X, Y, Anglex, Angley)

        {Objectanimator animator0=objectanimator.offloat (oviews. (), x,y);

        Objectanimator animator1=objectanimator.offloat (oviews. (), mhiddenviewmeasuredheightbegin);

        Objectanimator animator2=objectanimator.offloat (oviews. (), mhiddenviewmeasuredheightbegin);



        
        Objectanimator animator3=objectanimator.offloat (oviews. (), mhiddenviewmeasuredheightyclose);

        Objectanimator animator4=objectanimator.offloat (oviews. (), Anglex,f,angley);

        Objectanimator animator5=objectanimator.offloat (oviews. (), Anglex,f,angley);

        Objectanimator animator6=objectanimator.offloat (oviews. (), Anglex,f,angley);

        Objectanimator animator7=objectanimator.offloat (oviews. (), Anglex,f,angley);
        Animatorset = Animatorset ();
        . Setduration ();
        . Setinterpolator (Overshootinterpolator ()); . Playtogether (Animator0,ANIMATOR1,ANIMATOR2,ANIMATOR3,ANIMATOR4,ANIMATOR5,ANIMATOR6,ANIMATOR7);


    . Start (); }

Note is also more detailed, here to define a number of control properties, and also used the collection container, the entire animation effect is here to achieve, for beginners, this inside the effect is very subtle, so to run their own more detailed experience.

And then the opposite is exposing a click event, used for the event's callback,

    
      (Onmenuclicklistener Listener) {
        . Listener=listener;
    }

This is the main code for this control, and next I enclose all the code:

layout file:

menu_layout.xml
The layout file for the main page:
Next is the main interface code, main

/**

* Small Caps July 14, 2016 16:30:36

*

* @author Android Properties Animation--Smart Menu effect

*

* Related Blog Address http://blog.csdn.net/qq_25193681

*/

public class Main extends activity {

Private Mmenu menu;
@Override
protected void onCreate (Bundle savedinstancestate) {
    super.oncreate (savedinstancestate);
    Setcontentview (r.layout.main);



    menu= (Mmenu) Findviewbyid (r.id.mmenu);
    Menu.setonmenuclicklistener (New Onmenuclicklistener () {
        @Override public
        void Hyperlink () {
            Toast.maketext (Main.this, "clicked HYPERLINK", 0). Show ();
        @Override Public
        Void Home () {
            toast.maketext (main.this, "clicked Home", 0). Show ();
        @Override public
        Void Call () {
            toast.maketext (main.this, "Click Call", 0). Show ();}
    }

}

Mmenu

/**

* Small Caps July 14, 2016 16:30:36

*

* @author Android Properties Animation--Smart Menu effect

*

* Related Blog Address http://blog.csdn.net/qq_25193681

Related Article

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.