Two implementation methods of Android:todo application interaction (Behavior)

Source: Internet
Author: User

Recently writing TODO apps that involve Calendar and recyclerview interactions,

Demand:

1. Swipe up, Calendar is displayed as week

2. Week display mode, swipe down to display the month

3. The list falls to the position of the first item, and the Calendar is displayed as the week when it changes to show the month

4. Slide the list, the Calendar shrinks to show the week, if it has been shrunk, let the list slide, show more item.

Method One: The current use is to put the calendar and Recyclerview in a linearlayout, and then in the Dispatchtouchevent () method according to the swipe up and down the gesture to judge, and then let the calendar and Recycle Rview to interact.

Method Two: Now see another new solution is to use the Coordinatorlayout layout and then customize the Behavior to achieve the interaction of the Calendar and Recyclerview.

Calendarbehavior:

1  Public classCalendarbehaviorextendsCoordinatorlayout.behavior<monthpager> {2     Private intMtop;3 4 @Override5      Public BooleanLayoutdependson (coordinatorlayout parent, Monthpager Child, View dependency) {6         returnDependencyinstanceofRecyclerview;7     }8 9 @OverrideTen      Public BooleanOnlayoutchild (coordinatorlayout Parent, Monthpager Child,intlayoutdirection) { One Parent.onlayoutchild (Child, layoutdirection); A Child.offsettopandbottom (mtop); -         return true; -     } the  -     Private intDependentviewtop =-1; -  - @Override +      Public Booleanondependentviewchanged (coordinatorlayout parent, Monthpager Child, View dependency) { -         if(Dependentviewtop! =-1) { +             intDY = Dependency.gettop ()-dependentviewtop;//The view that dependency depends on (this example depends on the view is Recycleview) A             inttop =child.gettop (); at             if(Dy >-top) { -DY =-top; -             } -  -             if(Dy <-top-child.gettopmovabledistance ()) { -DY =-top-child.gettopmovabledistance (); in             } -  to child.offsettopandbottom (dy); +         } -Dependentviewtop = Dependency.gettop ();//Dependency theMtop =child.gettop (); *         return true; $     }Panax Notoginseng}

About customizing Behavior, Getting Started reference: http://blog.csdn.net/tabolt/article/details/51821933

Two implementation methods of Android:todo application interaction (Behavior)

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.