When we develop the Android app, there will be a lot of effects have to imitate iOS, recently in a page, the use of ScrollView, but to make the kind of iOS in ScrollView sliding. Floating in the ScrollView function button to hide, when the sliding end, the function button will be displayed again. Effects such as those seen in:
GIF is really hard to do, so just intercept a static diagram to show that when ScrollView is sliding. The button that floats below is hidden as an animation. When you stop sliding, the animation will return to the original position.
Idea: When the supervisor hears the ScrollView slide, the playback property animation is hidden. Play the opposite animation when the slide is finished. Bring the view back to its original location.
The code is as follows:
Package view;/********************************************************** * @ FileName: Customscrollview.java * @ file Rzq * @ Created: July 7, 2015 2:20:16 * @ File Description: Swipe to hide ScrollView * @ change history: July 7, 2015 create an initial version number ***************************************** /public class Customscrollview extends scrollview{/** * UI */private View contentview;/** * Data */privat E valueanimator 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;d ownscrolly = 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 exact part */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: A property animation is used primarily. Property animation is also very important, a certain learning and proficiency in the application.
Android imitation iOS, swipe to hide bottom scrollview