Slide 1

Slide 1 text

Mastering CoordinatorLayout Behaviors Dave Smith @devunwired +DaveSmithDev

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

AppBarLayout RecyclerView FloatingActionButton SnackbarLayout

Slide 4

Slide 4 text

@CoordinatorLayout.DefaultBehavior(FooterBarBehavior.class)
 public class FooterBarLayout extends FrameLayout {
 public FooterBarLayout(Context context) {
 super(context);
 } …
 } Behavior Basics

Slide 5

Slide 5 text

@CoordinatorLayout.DefaultBehavior(FooterBarBehavior.class)
 public class FooterBarLayout extends FrameLayout {
 public FooterBarLayout(Context context) {
 super(context);
 } …
 } Behavior Basics

Slide 6

Slide 6 text


 
 
 
 Behavior Basics

Slide 7

Slide 7 text


 
 
 
 Behavior Basics

Slide 8

Slide 8 text

public class FooterBarBehavior extends CoordinatorLayout.Behavior {
 
 public FooterBarBehavior() {
 //Used when attached to a view class as the default behavior
 }
 
 public FooterBarBehavior(Context context, AttributeSet attrs) {
 super(context, attrs);
 //Used when attached to a view via XML
 } …
 } Type of Attached View Behavior Basics

Slide 9

Slide 9 text

Layout Behaviors Scrolling Behaviors

Slide 10

Slide 10 text

Layout Behaviors View A Behavior View B layoutDependsOn() View B View A Behavior onMeasure() onLayout() onMeasureChild() onLayoutChild()

Slide 11

Slide 11 text

Layout Behaviors View A Behavior View B layoutDependsOn() View B View A Behavior Size/Position Change onDependentViewChanged() onDependentViewRemoved()

Slide 12

Slide 12 text

@Override
 public boolean layoutDependsOn(CoordinatorLayout parent,
 FloatingActionButton child, View dependency) { 
 return dependency instanceof Snackbar.SnackbarLayout;
 }
 
 @Override
 public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton child, View dependency) { 
 if (dependency instanceof Snackbar.SnackbarLayout) {
 updateFabTranslationForSnackbar(parent, child, dependency);
 } else if (dependency instanceof AppBarLayout) {
 updateFabVisibility(parent, (AppBarLayout) dependency, child);
 } 
 return false;
 } Layout Behaviors

Slide 13

Slide 13 text

@Override
 public boolean layoutDependsOn(CoordinatorLayout parent,
 FloatingActionButton child, View dependency) { 
 return dependency instanceof Snackbar.SnackbarLayout;
 }
 
 @Override
 public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton child, View dependency) { 
 if (dependency instanceof Snackbar.SnackbarLayout) {
 updateFabTranslationForSnackbar(parent, child, dependency);
 } else if (dependency instanceof AppBarLayout) {
 updateFabVisibility(parent, (AppBarLayout) dependency, child);
 } 
 return false;
 } Layout Behaviors

Slide 14

Slide 14 text

@Override
 public boolean layoutDependsOn(CoordinatorLayout parent,
 FloatingActionButton child, View dependency) { 
 return dependency instanceof Snackbar.SnackbarLayout;
 }
 
 @Override
 public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton child, View dependency) { 
 if (dependency instanceof Snackbar.SnackbarLayout) {
 updateFabTranslationForSnackbar(parent, child, dependency);
 } else if (dependency instanceof AppBarLayout) {
 updateFabVisibility(parent, (AppBarLayout) dependency, child);
 } 
 return false;
 } Layout Behaviors

Slide 15

Slide 15 text

@Override
 public boolean layoutDependsOn(CoordinatorLayout parent,
 FloatingActionButton child, View dependency) { 
 return dependency instanceof Snackbar.SnackbarLayout;
 }
 
 @Override
 public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton child, View dependency) { 
 if (dependency instanceof Snackbar.SnackbarLayout) {
 updateFabTranslationForSnackbar(parent, child, dependency);
 } else if (dependency instanceof AppBarLayout) {
 updateFabVisibility(parent, (AppBarLayout) dependency, child);
 } 
 return false;
 } Where did this come from? Layout Behaviors

Slide 16

Slide 16 text

Layout Behaviors

Slide 17

Slide 17 text

FAB anchored to AppBarLayout Layout Behaviors

Slide 18

Slide 18 text

AppBarLayout RecyclerView FloatingActionButton SnackbarLayout layoutDependsOn() app:layout_anchor

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

NestedScrollingChild NestedScrollingParent Touch Events Scroll Events Detour: Nested Scrolling

Slide 21

Slide 21 text

Touch Event Pre-Scroll Scroll Consumed Detour: Nested Scrolling NestedScrollingChild NestedScrollingParent

Slide 22

Slide 22 text

Touch Event Pre-Scroll Scroll Consumed Detour: Nested Scrolling RecyclerView CoordinatorLayout

Slide 23

Slide 23 text

Scrolling Behaviors View A Behavior View B NSChild onStartNestedScroll() onNestedPreScroll() onNestedScroll() View A Behavior View B NSChild Touch Scroll

Slide 24

Slide 24 text

Scrolling Behaviors View A Behavior View B NSChild onNestedPreFling() onNestedFling() onStartNestedScroll() View A Behavior View B NSChild Touch Fling

Slide 25

Slide 25 text

AppBarLayout RecyclerView FloatingActionButton SnackbarLayout layoutDependsOn() app:layout_anchor NestedScrolling Observer

Slide 26

Slide 26 text

Mastering CoordinatorLayout Behaviors @devunwired +DaveSmithDev milehighandroid.com wiresareobsolete.com