1
我想实现CoordinatorLayout与RecyclerView和TextView其中TextView将根据您如何滚动RecyclerView动画。但是我的自定义行为中的onDependentViewChanged
仅在我的视图第一次膨胀并且在此之后不被调用时才被调用几次,尽管我滚动了RecyclerView。CoordinatorLayout自定义行为不叫
我的行为:
public class Behavior extends CoordinatorLayout.Behavior<TextView> {
public Behavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, TextView child, View dependency) {
return dependency instanceof RecyclerView;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, TextView child, View dependency) {
return true;
}
}
我的XML:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="blahhhhhhhhhhh"
app:layout_behavior="com.mypackage.Behavior"/>
</android.support.design.widget.CoordinatorLayout>