When we develop Android app, there will be a lot of effects are need to imitate iOS, recently in a page, which used the ScrollView, but to make iOS that in ScrollView sliding, floating in the ScrollView function button to hide, when the sliding end, The function button is displayed again. The effect is as follows:
GIF is really bad, so you can only intercept a static diagram to show that when the ScrollView sliding, floating in the bottom of the button will be animated to hide, when the slide stops, it will be animated form back to the original position.
Idea: When the monitor hears the ScrollView slide, the playback property animation hides, when the sliding end plays the opposite animation, causes the view to return to the original position.
The code is as follows:
Package view;/********************************************************** * @ file name: Customscrollview.java * @ file Rzq * @ Created: July 7, 2015 2:20:16 * @ File Description: Swipe to hide ScrollView * @ Modify History: July 7, 2015 create initial version ******************************************** /public class Customscrollview extends scrollview{/** * UI */private View contentview;/** * Data */private V Alueanimator apperaanim;private valueanimator hiddenanim;private int downscrolly;private int moveScrollY;private Boolean Ishidding;public Customscrollview (context context, AttributeSet Attrs) {Super (context, attrs);} @Overrideprotected void Onfinishinflate () {if (Getchildcount () > 0) {contentview = Getchildat (0);}} @Overridepublic boolean ontouchevent (motionevent ev) {switch (ev.getaction ()) {case Motionevent.action_down: downscrolly = getscrolly (); Break;case MotionEvent.ACTION_MOVE:moveScrollY = getscrolly (); if (movescrolly! = downscrolly) {starthiddenanimation ();} Break;case MotionEvent.ACTION_UP:case MotionEvent.ACTION_CANCEL:moveScrollY = 0;downscrolly = 0;break;} return super.ontouchevent (EV);} public void Setanimationview (final View animationview) {/** * Create animation */hiddenanim = Valueanimator.offloat (0, Animationview.getheight ()); Hiddenanim.setduration (); Hiddenanim.settarget (Animationview); Hiddenanim.addupdatelistener (New Animatorupdatelistener () {@Overridepublic void Onanimationupdate (valueanimator Animation) {Animationview.settranslationy (Float) Animation.getanimatedvalue ());}); Hiddenanim.addlistener (New Animatorlisteneradapter () {@Overridepublic void Onanimationend (Animator animation) { Startapperaanimation ();} @Overridepublic void Onanimationstart (Animator animation) {ishidding = true;}}); Apperaanim = Valueanimator.offloat (Animationview.getheight (), 0); Apperaanim.setduration (+); apperaAnim.setTarget (Animationview); Apperaanim.addupdatelistener (new Animatorupdatelistener () {@Overridepublic void Onanimationupdate ( Valueanimator animation) {animationview.settranslationy (Float) Animation.getanimatedvalue ());}); Apperaanim.addlisteneR (New Animatorlisteneradapter () {@Overridepublic void Onanimationend (Animator animation) {ishidding = false;} @Overridepublic void Onanimationstart (Animator animation) {}}); private void Starthiddenanimation () {if (!hiddenanim.isrunning () &&!ishidding) {Hiddenanim.start ();}} private void Startapperaanimation () {if (!apperaanim.isrunning ()) {Apperaanim.start ();}} /** * Whether to swipe directly to the bottom */protected Boolean isscrolldown () {return getheight () + getscrolly () = = Contentview.getheight ();} /** * Whether to slide directly to the top */protected boolean Isscrollup () {return getscrolly () = = 0;}} /** * in activity Use */public class Customactivity extends Activity { private TextView TextView ; private CustomScrollView2 scrollview; @Override protected void OnCreate (Bundle savedinstancestate) { super.oncreate ( savedinstancestate); setcontentview (r.layout.custom_scrollview_layout); scrollview = (CustomScrollView2) Findviewbyid (R.id.scoll_view); textview = (textView) Findviewbyid (R.id.animation_view); } @Override public void Onwindowfocuschanged (Boolean hasfocus) { super.onwindowfocuschanged (hasfocus); if (hasfocus) { Scrollview.setanimationview (TextView); } }}Finally: The main use of a property animation, property animation is also very important, a certain learning and proficiency in the application.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android imitation iOS, swipe to hide bottom scrollview