onDependentViewChanged is called once only when dependency's visibility changed

Viewed 149

I try to implement a simple scenario: click on a button to show/hide the view(dependency). When the view(dependency) is shown, move the other view down. But onDependentViewChanged is only called once... Please help me to solve this issue.

<View
            android:id="@+id/child"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end|top"
            app:layout_behavior=".behavior.MoveDownBehavior">

<CustomizedView
        android:id="@+id/dependency"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top|center_horizontal"
        android:visibility="gone" />
class MoveDownBehavior<V : View>(context: Context, attrs: AttributeSet) :
    CoordinatorLayout.Behavior<V>(context, attrs) {

    // Rest of the code is the same
    override fun layoutDependsOn(parent: CoordinatorLayout, child: V, dependency: View): Boolean {

        return dependency is CustomizedView
    }

    override fun onDependentViewChanged(
        parent: CoordinatorLayout,
        child: V,
        dependency: View
    ): Boolean {
        Timber.e("dependency.visibility = ${dependency.visibility}")

        // TODO according dependency.visibility to move down or up the child view

        return super.onDependentViewChanged(parent, child, dependency)
    }
}

What's wrong with it?

0 Answers
Related