博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android View 1
阅读量:7229 次
发布时间:2019-06-29

本文共 1329 字,大约阅读时间需要 4 分钟。

hot3.png

App的跟节点是PhoneWindow$DecorView, DecorView是PhoneWindow下面的内部类实例。PhoneWindow$DecorView下面有三个child,分别是LinearLayout View@49da043和View@44ff410,一个表示 navigationBarBackground ,一个表示StatusBarBackground. Linearlayout下面有两个子child,分别是ViewStub实例和FrameLayout实例,FrameLayout有一个子类 Fragment(这就是平常创建项目的inflate  xml最外层)

什么所有的控件都是View的实例,

onCreate() 中调用 setContentView(R.layout.main),Andorid就会从PhoneWindow 到每一层 执行 测量,布局,绘制。所有子类都 先执行 super.XXX方法

几  1 

@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 
 
2  布局   布局 会用到
@Override public LayoutParams generateLayoutParams(AttributeSet attrs) { return new MarginLayoutParams(getContext(), attrs); }
 
自定义布局
 
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mListViews.clear(); mHieghts.clear(); //  int lineWidth = 0; int lineHeight = 0; int width = getWidth(); int count = getChildCount(); List
mList = new ArrayList<>(); for (int i = 0; i < count; i++) { View child = getChildAt(i); MarginLayoutParams mlp = (MarginLayoutParams) child.getLayoutParams(); int childWidth = child.getMeasuredWidth() + mlp.leftMargin + mlp.rightMargin; int childHeight = child.getMeasuredHeight() + mlp.topMargin + mlp.bottomMargin;
 
3布局完了之后 就会绘图

转载于:https://my.oschina.net/Dougien/blog/710097

你可能感兴趣的文章
lc682. Baseball Game
查看>>
重学前端-css选择器
查看>>
iOS开发之扫描二维码
查看>>
Android黑科技: 快速找到view所在的xml文件
查看>>
linux分区方案
查看>>
003-Java技术体系
查看>>
超轻量模板引擎
查看>>
JavaScript 复习之 Object对象的相关方法
查看>>
JAVA之流程控制语句
查看>>
Spring Boot(1)
查看>>
Winodws 10 美化与调优
查看>>
apache安装及多域名解析及域名代理
查看>>
什么是自动化运维 ? 自动化运维的设计思路以及实战
查看>>
Python练习实例100例(持续更新中)
查看>>
非父组件通信
查看>>
Electron系列文章-主进程与渲染进程
查看>>
高性能缓存服务器 nuster v1.8.8.2 和 v1.7.11.2 发布
查看>>
教你快速入门ES6
查看>>
Python 爬虫十六式 - 第六式:JQuery的假兄弟-pyquery
查看>>
宜昌a货翡翠,包头a货翡翠
查看>>