CoordinatorLayout|CoordinatorLayout --自定义Behavior 1
1.加入com.android.support:design:24.1.1包引用
文章图片
image.png 2.自定义 CoordinatorLayout.Behavior
public class EasyBehavior extends CoordinatorLayout.Behavior
public EasyBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, TextView child, View dependency) {
//告知监听的父控件是Button
return dependency instanceof Button;
}
@Override
//当 dependency(Button)变化的时候,可以对child(TextView)进行操作
public boolean onDependentViewChanged(CoordinatorLayout parent, TextView child, View dependency) {
child.setX(dependency.getX()+200);
child.setY(dependency.getY()+200);
child.setText(dependency.getX()+","+dependency.getY());
return true;
}
}
3.加载这个自定义的Behavior(注意包名要写对)
文章图片
image.png 【CoordinatorLayout|CoordinatorLayout --自定义Behavior 1】4.Textview将跟随Bottom移动了
文章图片
image.png
推荐阅读
- SpringBoot调用公共模块的自定义注解失效的解决
- python自定义封装带颜色的logging模块
- 列出所有自定义的function和view
- Spring|Spring Boot 自动配置的原理、核心注解以及利用自动配置实现了自定义 Starter 组件
- 自定义MyAdapter
- Android自定义view实现圆环进度条效果
- Flutter自定义view|Flutter自定义view —— 闯关进度条
- js保留自定义小数点
- django|django 自定义.save()方法
- 如何在Kubernetes|如何在Kubernetes 里添加自定义的 API 对象(一)