CoordinatorLayout.Behavior方法详解
之前一直没去针对的学习CoordinatorLayout.Behavior,最近在网上看了些文章,自己也研究了下,这里当作笔记记下。
都知道,CoordinatorLayout是协调子view行为的父控件,作为顶层控件使用,
那么要实现以上功能,我们需要重写Behavior内部的方法,先来看下Behavior中有哪些常用的方法:
public static abstract class Behavior{}
(1) public Behavior(Context context, AttributeSet attrs){}
构造方法,没啥好说的,为社么把它列出来呢,因为我们自定义Behavior时需要重写两个参数的构造方法,系统反射调用的就是这 个两个参数的构造方法,CoordinatorLayout.LayoutParams.parseBehavior()这个方法有兴趣可以去看下。
(2) public boolean layoutDependsOn(CoordinatorLayout parent, V child, View depedency){}
这个方法顾名思义,就是使用此Behavior的view想要依赖哪个view,说白了就是想要监听哪个view的状态变化。
parent: 根布局CoordinatorLayout
child: 使用此Behavior的view
depedency: 想要监听的view
返回值是一个布尔值,当depedentcy的类型是你想监听的View的类型时返回true,举个栗子,有如下布局:
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
