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)