当前位置: 首页 > wzjs >正文

怎么样做网站赚钱婚礼效果图网站

怎么样做网站赚钱,婚礼效果图网站,wordpress+模版+推荐,python如何做自己的网站文章目录 Android View#post()源码分析概述onCreate和onResume不能获取View的宽高post可以获取View的宽高总结 Android View#post()源码分析 概述 在 Activity 中,在 onCreate() 和 onResume() 中是无法获取 View 的宽高,可以通过 View#post() 获取 Vi…

文章目录

  • Android View#post()源码分析
    • 概述
    • onCreate和onResume不能获取View的宽高
    • post可以获取View的宽高
    • 总结

Android View#post()源码分析

概述

在 Activity 中,在 onCreate() 和 onResume() 中是无法获取 View 的宽高,可以通过 View#post() 获取 View 的宽高。

onCreate和onResume不能获取View的宽高

Activity 的生命周期都是在 ActivityThread 中,当调用 startActivity() ,最终会调用 ActivityThread#performLaunchActivity()。

// ActivityThread#performLaunchActivity()
// 核心代码:
private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) {Activity activity = null;java.lang.ClassLoader cl = appContext.getClassLoader();// 通过反射新建一个Activityactivity = mInstrumentation.newActivity(cl, component.getClassName(), r.intent);try {if (activity != null) {// 创建并初始化Windowactivity.attach(appContext, this, getInstrumentation(), r.token,r.ident, app, r.intent, r.activityInfo, title, r.parent,r.embeddedID, r.lastNonConfigurationInstances, config,r.referrer, r.voiceInteractor, window, r.activityConfigCallback,r.assistToken, r.shareableActivityToken);r.activity = activity;if (r.isPersistable()) {// 回调Activity#onCreate()mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState);} else {mInstrumentation.callActivityOnCreate(activity, r.state);}            } }return activity;
}
// ActivityThread#handleResumeActivity()
// 核心代码:
public void handleResumeActivity()(ActivityClientRecord r, boolean finalStateRequest,boolean isForward, String reason) {// 最终会回调Activity#onResume()if (!performResumeActivity(r, finalStateRequest, reason)) {return;}final Activity a = r.activity;if (r.window == null && !a.mFinished && willBeVisible) {r.window = r.activity.getWindow();View decor = r.window.getDecorView();decor.setVisibility(View.INVISIBLE); // 设置不可见ViewManager wm = a.getWindowManager();WindowManager.LayoutParams l = r.window.getAttributes();a.mDecor = decor;l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION;l.softInputMode |= forwardBit;if (r.mPreserveWindow) {a.mWindowAdded = true;r.mPreserveWindow = false;ViewRootImpl impl = decor.getViewRootImpl();if (impl != null) {impl.notifyChildRebuilt();}}if (a.mVisibleFromClient) {if (!a.mWindowAdded) {a.mWindowAdded = true;// 添加View,开始View的操作wm.addView(decor, l);} else { a.onWindowAttributesChanged(l);}} }   
}

说明:Activity 先执行 onCreate(),再执行 onResume(),最后才调用 wm.addView() 将 DecorView 添加到视图中,也就是从这里才开始执行 View 测量布局绘制流程。简单说 View 的流程晚于 onResume()。

post可以获取View的宽高

// View#post()
public boolean post(Runnable action) {final AttachInfo attachInfo = mAttachInfo;if (attachInfo != null) {// 如果attachInfo不为null,表示View已经添加到Window,直接通过Handler发送到主线程队列return attachInfo.mHandler.post(action);}// 如果attachInfo为null,表示View未添加到Window,暂存在mRunQueue中getRunQueue().post(action);return true;
}private HandlerActionQueue getRunQueue() {if (mRunQueue == null) {mRunQueue = new HandlerActionQueue();}return mRunQueue;
}

说明:在 onCreate() 和 onResume() 中调用 View#post(),最终都会调用 getRunQueue().post(action)。

wm.addView(decor, l) 执行流程:

  • 调用 WindowManagerImpl#addView()。
  • 调用 WindowManagerGlobal#addView()。
  • 执行 new ViewRootImpl,创建 root 对象(布局管理器),并在内部创建 mAttachInfo 对象、Handler 对象。
  • 调用 ViewRootImpl#setView()。
// ViewRootImpl#setView()
public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView, int userId) {synchronized (this) {if (mView == null) {mView = view;// 请求布局,最终调用ViewRootImpl#performTraversals()requestLayout();           try {// 通过Binder调用WMS添加Windowres = mWindowSession.addToDisplayAsUser(mWindow, mWindowAttributes,getHostVisibility(), mDisplay.getDisplayId(), userId,mInsetsController.getRequestedVisibilities(), inputChannel, mTempInsets,mTempControls);               }   }}
}
// ViewRootImpl#performTraversals()
private void performTraversals() {final View host = mView;// 调用View#dispatchAttachedToWindow()分发mAttachInfo    host.dispatchAttachedToWindow(mAttachInfo, 0);// 测量流程performMeasure(childWidthMeasureSpec, childHeightMeasureSpec);// 布局流程performLayout(lp, mWidth, mHeight);// 绘制流程performDraw()
}
// View#dispatchAttachedToWindow()
void dispatchAttachedToWindow(AttachInfo info, int visibility) {mAttachInfo = info;// 执行缓存任务if (mRunQueue != null) {mRunQueue.executeActions(info.mHandler);mRunQueue = null;}  
}
// HandlerActionQueue#executeActions()
public class HandlerActionQueue {private HandlerAction[] mActions;public void executeActions(Handler handler) {synchronized (this) {final HandlerAction[] actions = mActions;for (int i = 0, count = mCount; i < count; i++) {final HandlerAction handlerAction = actions[i];handler.postDelayed(handlerAction.action, handlerAction.delay);}mActions = null;mCount = 0;}}
}

说明:执行 mRunQueue.executeActions(),会将所有缓存的任务发送到 handler 中,等待主线程执行完 performTraversals() 方法后,就会执行 mActions 中的任务,这时就可以获取到 View 的宽高。

总结

执行流程:

  • Activity#onCreate()
  • Activity#onResume()
  • WindowManagerImpl#addView()
  • new ViewRootImpl()
  • ViewRootImpl#setView()
  • View的测量流程
  • View的布局流程
  • View的绘制流程
  • WMS添加Window
  • 获取View的宽高

文章转载自:

http://bmvgAQAy.ghryk.cn
http://LVVnWBt2.ghryk.cn
http://gScBTyTE.ghryk.cn
http://y5WeZVGo.ghryk.cn
http://7j9FCv9M.ghryk.cn
http://Vb5FLXUY.ghryk.cn
http://m66Ttgjk.ghryk.cn
http://NoOxuqbn.ghryk.cn
http://dr9tMDVI.ghryk.cn
http://K5FWPcCr.ghryk.cn
http://M4h4LHAe.ghryk.cn
http://W0Vax6w3.ghryk.cn
http://tEy0UQkp.ghryk.cn
http://bkC0UQbQ.ghryk.cn
http://2gGFNEoG.ghryk.cn
http://zgHgRZQc.ghryk.cn
http://rgYh5N7W.ghryk.cn
http://ylM4T0nc.ghryk.cn
http://b3B9IRMm.ghryk.cn
http://xG24UUO0.ghryk.cn
http://V0M5rueh.ghryk.cn
http://Aj2PFqYG.ghryk.cn
http://tm9AZrMC.ghryk.cn
http://UnRLYv2p.ghryk.cn
http://rEynSlOS.ghryk.cn
http://kg2Vnr28.ghryk.cn
http://xAD406Ss.ghryk.cn
http://7Q5HZL0A.ghryk.cn
http://cR7KkNJo.ghryk.cn
http://ztXKuQ5l.ghryk.cn
http://www.dtcms.com/wzjs/712196.html

相关文章:

  • 班组建设展板哪个网站有建设银行电子银行网站
  • 广州网站制作网站服务器上的php4.0网站连接sql2005服务器连接不上
  • 哪个网站可以做视频播放器影视头像logo设计
  • 华强北 网站建设网站建设 接单
  • 论坛类网站如何备案wordpress 和织梦
  • 视频网站开发项目青岛官网seo技术厂家
  • 网站转微信小程序开发这么做输入文字的网站
  • 企业不做网站商业论坛网
  • 找做网站个人做旅游网站
  • 西安高端网站开发网站营销 海外
  • 珠海酒店网站建设网站设计的书
  • 湖南品牌网站建设高端私人订制网站建设
  • 那个网站可教做课件好舟山网站建设有哪些
  • 如何做好网站建设内容的策划推广任务平台
  • 做网站学网站运营的作用
  • 电影项目做产品众筹哪个网站好网页无法访问摄像头
  • 宿松做网站手机免费表格软件app
  • 猪八戒网网站开发需求thinkphp网站后台模板
  • 柳州网站建设价格免费咨询做网站
  • wordpress视频网站用什么播放器成都旅游团
  • 兰州网站建设q479185700惠网站手机优化
  • 建设部网站 自住房推广软件的种类
  • 贵阳网站搜索优化黄岩做网站
  • 德宏北京网站建设建设银行的网站为什么登不上
  • 免费企业建站源代码韩国网站
  • 中国3大做外贸的网站甘肃住房与城乡建设部网站
  • 网站开发筛子游戏wordpress 底部 copyright 时间
  • 中国糕点网页设计网站邢台做移动网站找谁
  • 一个网站怎么做网站备案是需要去哪里做
  • 傻瓜式建个人网站盘多多网盘资源库