Android API之onLayout, onMeasure

摘要:
Intb)执行布局操作时调用onLayout方法。具有Children的子类需要重写onLayout方法并调用每个Child的layout方法。参数更改表示视图的大小或位置已更改。方法measure(int,voidandroid.view.ViewGroup.layout(intl,

android.view.ViewGroup

protected void onLayout(boolean changed, int l, int t, int r, int b)

执行layout操作时调用onLayout方法。View要给它的每个Child设定size和position。拥有Children的子类需要重写onLayout方法并且调用每个Child的layout方法。

参数changed表示view的size或position发生变化。参数l, t, r, b分别表示相对于parent的left, top, right, bottom position。

 

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

测量View及其Content,确定measuredWidth和measuredHeight。在方法measure(int, int)中调用。重写onMeasure方法时,需要调用方法setMeasuredDimension(int, int),存储View的measuredWidth和measuredHeight。若存储失败,方法measure(int, int)会抛出异常IllegalStateException。可以调用super.onMeasure(int, int)方法。

除非MeasureSpec准许更大的size,否则measure的默认实现是background size。子类重写onMeasure(int, int)提供Content的更佳测量。如果onMeasure被重写,子类必须保证measuredWidth和measuredHeight至少是view的minHeight和minWidth。minHeight/Width通过getSuggestedMinimumHight/Width()获取。

参数width/heightMeasureSpec表示parent强加的horizontal/vertical space要求。

 

void android.view.ViewGroup.layout(int l, int t, int r, int b)

给view及其descendants设定size和position。它正是layout机制的第2个步,每个parent调用它的chlidren的layout操作。使用在measure阶段测量得到的size和position数据完成layout操作。拥有child的子类必须重写onLayout方法,调用每个child的layout操作。

 

void android.view.ViewGroup.measureChildren(int widthMeasureSpec, int heightMeasureSpec)

请View的所有children测量themseles, 测量依据是View的MeasureSpec和padding。忽略处于GONE状态的children,是否GONE状态由getChildMeasureSpec来确定。

参数width/heightMeasureSpec表示view的width/height要求。

免责声明:文章转载自《Android API之onLayout, onMeasure》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇CentOS查询端口占用和清除端口占用的程序U9培训记录下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

iview table表头自定义筛选

自定义search input: const searchInput = (h, params, that) =>( <span class="search-area"> <span>{params.column.title}</span> <div class="pop-search-w...

unity3D shader学习

网络信息汇总   unity内部阴影的使用 阴影的投射只要有shadow caster通道即可;阴影接受的计算: 方法1 1 #pragma multi_compile_fwdbase 2 #include “AutoLight.cginc” 3 SHADOW_COORDS(1) // put shadows data into TEXCOO...

h5移动端获取当前手机位置的方法,js纯获取,非原生

mounted() { var mapObj = new AMap.Map('iCenter'); mapObj.plugin('AMap.Geolocation', function() { let geolocation = newAMap.Geolocation({...

一起学Android之ContentProvider

本文主要讲解在Android开发中ContentProvider的常规用法,仅供学习分享使用,如有不足之处,还请指正。 访问一个ContentProvider 在Android开发中,应用程序通过ContentResolver(内容解析器)从ContentProvider(内容提供者)中获取数据,ContentResolver提供访问ContentProv...

reuqest模块及UA反扒机制

requests模块 爬虫中一个基于网络请求的模块 pip install requests 作用:模拟浏览器发起请求 编码流程: 1 . 指定url 2 . 发起请求 3 . 获取响应数据(爬取到的页面源码数据) 4 . 进行持久化存储 简单例子: #指定爬取的url (以搜狗为例) url = "https://www.sogou.com"...

thinkphp过滤xss

什么是XSS:这里通俗的讲,就像是SQL注入一样,XSS攻击也可以算是对HTML和JS的一种注入。你本来希望得到是从用户那得到一段有用的文本文字,但用户提交给你的却是别有用心的可执行javasc ript或其它脚本(这里并没有把破坏样式或文档文本当作攻击),当你再把这些提交的内容显示到页面上时,XSS攻击就发生了。 关于XSS的攻击方式和场景层出不穷,本...