美文网首页
关于CoordinatorLayout

关于CoordinatorLayout

作者: 零宽度接合 | 来源:发表于2016-12-15 14:51 被阅读28次

在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使用在需要跟随变化的控件上

相关文章

网友评论

      本文标题:关于CoordinatorLayout

      本文链接:https://www.haomeiwen.com/subject/viqgmttx.html