在Behavior中,被观察View 也就是事件源被称为denpendcy,而观察View,则被称为child。
http://blog.csdn.net/wingichoy/article/details/52298704
publicclassEasyBehaviorextendsCoordinatorLayout.Behavior {//这里的泛型是child的类型,也就是观察者ViewpublicEasyBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Overridepublicboolean layoutDependsOn(CoordinatorLayoutparent, TextView child, View dependency) {//告知监听的dependency是ButtonreturndependencyinstanceofButton;
}
@Override//当 dependency(Button)变化的时候,可以对child(TextView)进行操作publicboolean onDependentViewChanged(CoordinatorLayoutparent, TextView child, View dependency) {
child.setX(dependency.getX()+200);
child.setY(dependency.getY()+200);
child.setText(dependency.getX()+","+dependency.getY());returntrue;
}
}
behavior使用在需要跟随变化的控件上