As the ScrollView slide, the animation view is gradually executed

Source: Internet
Author: User

Today is the realization of a small function of things. Look:

Implementation mode: 1. Customize the ScrollView replication Onscrollchange method to calculate the position of the slide. 2. Custom interface, through the interface to control in the ScrollView, sliding the height of the progress. 3. Perform the animation in the custom view.

Code implementation: 1. ScrollView The most important code only to calculate the sliding position of the code, in fact, is very simple, to get the number of child view, each time to go for the loop, to calculate the position of the word view, and the current ScrollView top bottom code:
@Override      protected   void  onscrollchanged ( Span style= "margin:0px; padding:0px; Color:rgb (127,0,85) "> int  l,  int  t,  int  oldl,  int  oldt)  { Super. onscrollchanged (L, T, OLDL, Oldt); int currentbottom = t + height ; int currenttop = t;Log. e ("Slide", "Onscrollchange");        For ( int i = 0; i < childCount; i++) {View Childview = contentlayout. Getchildat (i); if (! ( Childview instanceof easyslideinter)) { continue ;            } int childtop = Childview.gettop (); int childbottom = Childview.getbottom (); int childheight = Childview.getheight ();easyslideinter inter = (easyslideinter) Childview; if (Currenttop > Childtop && currenttop < Childbottom) {inter.contentslide (countprogress (Currenttop, Childbottom, Childheight));} Else if (Currentbottom > Childtop && currentbottom < Childbottom) {inter.contentslide (100-countprogress (Currentbottom, Childbottom, Childheight));} Else if(childtop >= currenttop && childbottom <= currentbottom) {inter.resetcontent ();            }        }}


By Childview the top position and the current top position of the ScrollView to determine which sub-view is slowly appearing, calculate the progress passed to the child view.
In fact, the final code is such a paragraph, the execution of the animation in the child view of the interface method to do. I put on a sub-view implementation:     @Override Public void contentslide ( int progress) { textanimator. Setcurrentplaytime (progress); backanimator. Setcurrentplaytime (progress);    } @Override Public void resetcontent () { textanimator. Setcurrentplaytime (+); backanimator. Setcurrentplaytime (+);    }              Private  < Span style= "margin:0px; padding:0px; Color:rgb (127,0,85) "> void  initanimation () {         textAnimator  = objectanimator. ofint (text ,  " TextColor ",  color. BLUE  , color. RED );   textanimator. Setevaluator ( new argbevaluator ()); textanimator. setduration (+); textanimator. Setinterpolator ( new linearinterpolator ());         backanimator = objectanimator. Ofint ( This, "BackgroundColor", Color.) BLACK , Color. BLUE , Color.  BLACK); backanimator. Setevaluator ( new argbevaluator ()); backanimator. setduration (+); backanimator. Setinterpolator ( new linearinterpolator ());            }
Implement the two interface methods, in both methods, to control the progress of the animation. Very simple, no longer a cumbersome narrative. SOURCE Download: Baidu Network disk: Http://pan.baidu.com/s/1dDtVzSt
GitHub Address: Https://github.com/flyme2012/EasySlide

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

As the ScrollView slide, the animation view is gradually executed

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.