The implementation of the Android property animation layout of the Drop-down expansion

Source: Internet
Author: User

A few days ago, we did some Android animations (http://blog.csdn.net/qq_25193681/article/details/51777248) and got a sense of Android's tweens. But after Android's 3.0, Google has come up with a framework for property animations that will help us achieve richer animations. So in order to keep up with the pace of technology, today we'll talk about attribute animation.

The demand for this time is this: When you click on a view, show the hidden view below, to achieve this function, you need to set the visibility property of V iew gone as visible, but this process is instantaneous, and can not achieve the effect we want. Therefore, property animation is a good solution.

Put the effect on first.

The first one:

The second one:

The front one is hidden, and the latter one is displayed. When you click on this arrow, to toggle the display or hide,

Now start coding:

The layout file is as follows

 = = = = = = = > = = = = = > =
        = = = = = =/> > = =
            = = = = = = = = = > = = = = =
        =/> = = = =/> > =
            = = = = = > = = = = = = = = = = = = =

            = = =/> = = = = =/> >
            = = = = = = = = = = = = = = > = = = = =/> > 

There's not much code, it's simple, three linear layouts with their own controls loaded, and IDs set up. The button is a linear layout, using the onclick itself click event. Next, when you click on this linear layout, the controls that need to be hidden end up at a height, which is our target value, and it just needs to be converted to pixels through the DP in the layout.


 + );

Here's 120 is the height defined in our layout.

Then add an animation effect to the process.

    Valueanimator animator = Valueanimator.ofint (start, end);
        Animator.addupdatelistener (Animatorupdatelistener () {

            @Override
              (valueanimator arg0) {
                  = () Arg0.getanimatedvalue ();
                Viewgroup.layoutparams layoutparams = V.getlayoutparams ();
                Layoutparams.height =;
                V.setlayoutparams (Layoutparams);

            }
        );

Through such a simple valueanimator, it is easy to achieve the display and hidden animation effect.

Here is the complete code.

 Android.animation.Animator;
 Android.animation.AnimatorListenerAdapter;
 Android.animation.ValueAnimator;
 Android.animation.ValueAnimator.AnimatorUpdateListener;
 Android.os.Bundle;
 android.support.v7.app.ActionBarActivity;
 Android.view.View;
 Android.view.ViewGroup;
 Android.view.Window;
 Android.view.animation.Animation;
 Android.view.animation.RotateAnimation;
 Android.widget.ImageView;

     Android.widget.LinearLayout;

      {LinearLayout mhiddenlayout;

      mdensity;

     Mhiddenviewmeasuredheight;

    
      ImageView MIV; (Bundle savedinstancestate)
        {. OnCreate (savedinstancestate);
        Requestwindowfeature (Window.feature_no_title);
        Setcontentview (R.layout.activity_main); url:http://www.bianceng.cn/os/extra/201608/50381.htm mhiddenlayout = (linearlayout) findViewById (R.id.linear_hid
        DEN);

        MIV = (ImageView) Findviewbyid (R.ID.MY_IV);

        Mdensity = Getresources (). Getdisplaymetrics (). density; MhiddenviewmeaSuredheight = () (mdensity * +);
            } (View v) {(mhiddenlayout.getvisibility () = View.gone) {animateopen (mhiddenlayout);
        Animationivopen ();
            } {animateclose (mhiddenlayout);
        Animationivclose ();
        } (View v) {v.setvisibility (view.visible);
        Valueanimator animator = Createdropanimator (V, mhiddenviewmeasuredheight);

    Animator.start (); } () {rotateanimation animation = Rotateanimation (,, Animation.relative_to_self, F, anim ation.
        Relative_to_self, F);
        Animation.setfillafter ();
        Animation.setduration ();
    Miv.startanimation (animation); } () {rotateanimation animation = Rotateanimation (,, Animation.relative_to_self, F, anim ation.
        Relative_to_self, F);
        Animation.setfillafter ();
        Animation.setduration (); Miv.sTartanimation (animation);
        } (view view) {origheight = View.getheight ();
        Valueanimator animator = Createdropanimator (view, Origheight,); Animator.addlistener (Animatorlisteneradapter () {(animator animation) {VIEW.S
            Etvisibility (View.gone);
        }

        });
    Animator.start ();
        } valueanimator (View V, start, end) {Valueanimator animator = Valueanimator.ofint (start, end);
                 Animator.addupdatelistener (Animatorupdatelistener () {(Valueanimator arg0) {
                Value = () Arg0.getanimatedvalue ();
                Viewgroup.layoutparams layoutparams = V.getlayoutparams ();
                Layoutparams.height = value;

            V.setlayoutparams (Layoutparams);
         }
        });
    Animator; }

}
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.