The scaling effect of the Android floating button

Source: Internet
Author: User

When doing the project want to add a bit of dynamic, so there is the following effect:

Implementation is also very simple, through the property animation and Recyclerview sliding combination is very good implementation.

By adding a swipe listener to the Recycleview: handles the animation by scrolling the difference value

Mrecyclerview.addonscrolllistener (NewRecyclerview.onscrolllistener () {@Override Public voidOnscrollstatechanged (Recyclerview Recyclerview,intnewstate) {} @Override Public voidOnscrolled (Recyclerview Recyclerview,intDxintdy) {                if(Dy >0) {Hidenfabanim (); }Else{Showfabanim (); }            }        });

The two animations are as follows:

/** * Animated Hide Floating button*/    Private voidHidenfabanim () {if(!isfabanimg && Mactionbutton! =NULL&& mactionbutton.getvisibility () = =view.visible) {Animator Animator= Objectanimator.offloat (Mactionbutton,"Translationy", 0f, 100f); Animator.setduration ( -); Animator.addlistener (NewAnimator.animatorlistener () {@Override Public voidOnanimationstart (Animator animation) {isfabanimg=true; } @Override Public voidonanimationend (Animator animation) {isfabanimg=false;                    Mactionbutton.setvisibility (View.gone); } @Override Public voidOnanimationcancel (Animator animation) {isfabanimg=false; } @Override Public voidonanimationrepeat (Animator animation) {}});            Animator.start (); }    }    /** * Animated display floating button*/    Private voidShowfabanim () {if(Mactionbutton! =NULL&&!isfabanimg && mactionbutton.getvisibility () = =view.gone) {Animator Animator= Objectanimator.offloat (Mactionbutton,"Translationy", 100f,0f); Animator.setduration ( -); Animator.addlistener (NewAnimator.animatorlistener () {@Override Public voidOnanimationstart (Animator animation) {isfabanimg=true; } @Override Public voidonanimationend (Animator animation) {isfabanimg=false; } @Override Public voidOnanimationcancel (Animator animation) {isfabanimg=false; } @Override Public voidonanimationrepeat (Animator animation) {}});            Mactionbutton.setvisibility (view.visible);        Animator.start (); }    }

The distance given in the animation to move out of the screen and display on the screen is 100, the value is not so deterministic, the item needs to be calculated by the size of the screen density, in order to adapt to better sliding effect, define a

The isfabanimg variable, used to clarify the state of the animation, avoids repeated display or hidden animations.

Visible in Android to achieve some of the small effect is very convenient

The scaling effect of the Android floating button

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.