Create dependencies between Views

suggest change

You can use the CoordinatorLayout.Behavior to create dependencies between views. You can anchor a View to another View by:

For example, in order to create a Behavior for moving an ImageView when another one is moved (example Toolbar), perform the following steps:

public class MyBehavior extends CoordinatorLayout.Behavior<ImageView> {...}
public boolean layoutDependsOn(CoordinatorLayout parent, 
        ImageView child, View dependency) {
    // Returns true to add a dependency.
    return dependency instanceof Toolbar;
public boolean onDependentViewChanged(CoordinatorLayout parent, ImageView child, View dependency) {
    // Implement here animations, translations, or movements; always related to the provided dependency.
    float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight()); 

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents