监听视图树 OnGlobalLayoutListener
前奏:在哪里可以获取到View的宽高
官方文档简介
内部接口
- 回调方法 public void onDraw()
- Interface definition for a callback to be invoked when the view tree is about to将要 be drawn.
- At this point, views cannot be modified in any way.
- Unlike with OnPreDrawListener, this method cannot be used to cancel the current drawing pass.
- An OnDrawListener listener cannot be added or removed from this method.
OnGlobalFocusChangeListener:当在一个视图树中的焦点状态发生改变时回调
- 回调方法 public void onGlobalFocusChanged(View oldFocus, View newFocus);
- Interface definition for a callback to be invoked when the focus state焦点状态 within the view tree changes.
- When the view tree transitions from touch mode to non-touch mode, oldFocus is null.
- When the view tree transitions from non-touch mode to touch mode, newFocus is null.
- When focus changes in non-touch mode (without transition from or to touch mode) either oldFocus or newFocus can be null.
OnGlobalLayoutListener:当在一个视图树中全局布局发生改变或者视图树中的某个视图的可视状态发生改变时回调
- 回调方法 public void onGlobalLayout();
- Interface definition for a callback to be invoked when the global layout state布局状态 or the visibility of views within the view tree changes.
OnPreDrawListener:当一个视图树将要绘制时回调
- 回调方法 public boolean onPreDraw(); Return true to proceed with the current drawing pass, or false to cancel.
- Interface definition for a callback to be invoked when the view tree is about to将要 be drawn.
- At this point, all views in the tree have been measured and given a frame.
- Clients can use this to adjust适应 their scroll bounds or even to request a new layout before drawing occurs.
OnScrollChangedListener:当一个视图树中的一些组件发生滚动时回调
- 回调方法 public void onScrollChanged();
- Interface definition for a callback to be invoked when something in the view tree has been scrolled滚动.
OnTouchModeChangeListener:当一个视图树的触摸模式发生改变时回调
- 回调方法 public void onTouchModeChanged(boolean isInTouchMode); True if the view hierarchy is now in touch mode, false otherwise.
- Interface definition for a callback to be invoked when the touch mode触摸方式 changes.
OnWindowAttachListener:
- 回调方法 public void onWindowAttached(); 和 public void onWindowDetached();
- Interface definition for a callback to be invoked when the view hierarchy视图数 is attached to and detached from its window.
OnWindowFocusChangeListener:
- 回调方法 public void onWindowFocusChanged(boolean hasFocus); Set to true if the window is gaining focus, false if it is losing focus.
- Interface definition for a callback to be invoked when the view hierarchy's window focus state窗口焦点 changes.
公共方法
- void addOnDrawListener(ViewTreeObserver.OnDrawListener listener):Register a callback to be invoked when the view tree is about to be drawn.
- void addOnGlobalFocusChangeListener(ViewTreeObserver.OnGlobalFocusChangeListener listener):Register a callback to be invoked when the focus state within the view tree changes.
- void addOnGlobalLayoutListener(ViewTreeObserver.OnGlobalLayoutListener listener):Register a callback to be invoked when the global layout state or the visibility of views within the view tree changes
- void addOnPreDrawListener(ViewTreeObserver.OnPreDrawListener listener):Register a callback to be invoked when the view tree is about to be drawn
- void addOnScrollChangedListener(ViewTreeObserver.OnScrollChangedListener listener):Register a callback to be invoked when a view has been scrolled.
- void addOnTouchModeChangeListener(ViewTreeObserver.OnTouchModeChangeListener listener):Register a callback to be invoked when the invoked when the touch mode changes.
- void addOnWindowAttachListener(ViewTreeObserver.OnWindowAttachListener listener):Register a callback to be invoked when the view hierarchy is attached to a window.
- void addOnWindowFocusChangeListener(ViewTreeObserver.OnWindowFocusChangeListener listener):Register a callback to be invoked when the window focus state within the view tree changes.
- void removeGlobalOnLayoutListener(ViewTreeObserver.OnGlobalLayoutListener victim):This method was deprecated in API level 16. Use removeOnGlobalLayoutListener instead
- void removeOnGlobalLayoutListener(ViewTreeObserver.OnGlobalLayoutListener victim):Remove a previously installed global layout callback
- final void dispatchOnDraw():Notifies registered listeners that the drawing pass is about to start.
- final void dispatchOnGlobalLayout():Notifies registered listeners that a global layout happened.
- final boolean dispatchOnPreDraw():Notifies registered listeners that the drawing pass is about to start.
- boolean isAlive():Indicates指示、判断 whether this ViewTreeObserver is alive是否可用.
案例:获取View的宽高
}
监听视图树 OnGlobalLayoutListener的更多相关文章
- 监听视图树 ViewTreeObserver 获取View的宽高
前奏:在哪里可以获取到View的宽高 我们知道,在onCreate方法执行完毕以后,View才开始被测量,所以我们在onCreate方法里面通过view.getWidth()或view.getMeas ...
- sencha touch 监听视图切换动画(animation)
var animation = this.getLayout().getAnimation(); //添加监听 animation.on({ scope: this, animationend: 'o ...
- MutationObserver 监听DOM树变化
1 概述 Mutation observer 是用于代替 Mutation events 作为观察DOM树结构发生变化时,做出相应处理的API.为什么要使用mutation observer 去代替 ...
- MutationObserver 监听 DOM 树变化
MutationObserver 是用于代替 MutationEvents 作为观察 DOM 树结构发生变化时,做出相应处理的 API .为什么要使用 MutationObserver 去代替 Mut ...
- android activity中监听View测量完成的4种方式
在开发中经常碰到需要在activity初始化完成后获得控件大小的情况. 但是这个操作我们不能在oncreate.onresume等生命周期方法中调用,因为我们不知道何时view才能初始化完成 为此,特 ...
- #你好Unity3D#Hierarchy视图监听gameObject点击事件
今天无意间又找到了个好方法 1 2 3 4 5 6 7 8 9 10 [InitializeOnLoadMethod] static void Start () { Selection.s ...
- [Swift通天遁地]三、手势与图表-(2)监听手势事件自由拖动图像视图
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 使用swipecard实现卡片视图左右滑动监听以及点击监听
前言: 大家好,今天给大家介绍安卓一种特别实用有很酷炫的组件swipecard,当然这并不是安卓爸爸创造的,这是国内的一个我认为是大牛的一个人随便写着玩儿搞出来了,我看了他的代码介绍已经很清晰了,但 ...
- AndroidUI 视图动画-混合动画效果 (AnimationSet)/动画效果监听
在前面介绍了几种动画效果:透明动画效果(AlphsAnimation).移动动画效果(TranslateAnimation).旋转动画效果(RotateAnimation).缩放动画效果(ScaleA ...
随机推荐
- 【转】lua random()
先来看看这两段代码: ① math.randomseed(os.time())for i=1,10 do n = math.random(10) print(n) 运行结果是: 63210754341 ...
- Android JNI 之 环境安装
在配置环境之前,我们得了解 JNI 和NDK JNI JNI是Java Native Interface的缩写,中文为JAVA本地调用.它提供了若干的API实现了和Java和其他语言的通信(主要是C& ...
- ar命令和nm命令(建库!)
ar 命令详解 今天,跟着我们的技术大牛学了不少东西,首先就是这个ar命令啦. 当我们的程序中有经常使用的模块,而且这些模块在其他程序中也会用到,为了实现代码重用减少软件开发周期,我们可以将它们生成库 ...
- SASS type-of 函数
今儿写个type-of,算是备忘录吧. 1.number type-of(0) // number type-of(1px) // number 2.string type-of(a) // stri ...
- memcache锁
锁的使用,一般情况是针对并发或者我们希望程序(crontab的job)串行处理,我们加锁的办法有很多,像文件锁,数据库锁,或者memcache锁,这里关注一下memcache锁,针对memcache锁 ...
- MYSQL管理之主从同步管理 转载
MYSQL主从同步架构是目前使用最多的数据库架构之一,尤其是负载比较大的网站,因此对于主从同步的管理也就显得非常重要,新手往往在出现主从同步错误的时候不知道如何入手,这篇文章就是根据自己的经验来详细叙 ...
- JavaScript 学习-变量的作用域和块级作用域
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- mac 下 配置 阿帕奇
1.从 tomcat 官网(http://tomcat.apache.org/download-90.cgi)下载 完整的 tomcat包. 2.将红框中的包下载完,然后解压到任意一个目录,将其命名为 ...
- FileUpload 改变控件显示的文字
浏览
- C#程序设计基础——常量
C#程序设计基础——常量 常量是在编译时已知,并且在程序的生存期内不发生更改的不可变值.常量使用const修饰符进行声明. 常量必须在声明时初始化,且常量的类型必须为以下类型之一:sbyte/byte ...