Android setContentView源码阅读
2021/9/22 20:45:42
本文主要是介绍Android setContentView源码阅读,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
阅读源码查看系统如何加载布局
Acticity setContentView源码阅读
public void setContentView(@LayoutRes int layoutResID) { getWindow().setContentView(layoutResID); initWindowDecorActionBar(); }
点击去发现是个抽象类
public abstract void setContentView(@LayoutRes int layoutResID);
1、通过getWindow()找到具体的实现类PhoneWindow
mWindow = new PhoneWindow(this, window);
2、查看PhoneWindow如何具体加载布局 继续看代码
@Override public void setContentView(int layoutResID) { if (mContentParent == null) { installDecor(); } mLayoutInflater.inflate(layoutResID, mContentParent);
3、查看installDecor(); 里面代码 返回一个DecorView,DecorView继承FrameLayout
//赋值给了Phonewindow成员变量 mDecor protected DecorView generateDecor(int featureId) { ... return new DecorView(context, featureId, this, getAttributes()); }
4、继续看里面installDecor又干了什么事情
private void installDecor() { mForceDecorInstall = false; if (mDecor == null) { mDecor = generateDecor(-1); mDecor.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); mDecor.setIsRootNamespace(true); if (!mInvalidatePanelMenuPosted && mInvalidatePanelMenuFeatures != 0) { mDecor.postOnAnimation(mInvalidatePanelMenuRunnable); } } else { mDecor.setWindow(this); } if (mContentParent == null) { // 构建布局 mContentParent = generateLayout(mDecor); 。。。
protected ViewGroup generateLayout(DecorView decor) { // Apply data from current theme. // 构建布局主要代码 mDecor.startChanging(); mDecor.onResourcesLoaded(mLayoutInflater, layoutResource); ViewGroup contentParent = (ViewGroup)findViewById(ID_ANDROID_CONTENT); // 构建系统布局
``
这篇关于Android setContentView源码阅读的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-30uniAPP 实现全屏左右滚动滚动的效果-icode9专业技术文章分享
- 2024-06-30如何在本地使用授权或插件-icode9专业技术文章分享
- 2024-06-30伪静态规则配置方法汇总-icode9专业技术文章分享
- 2024-06-29易优CMS安装常见问题汇总-icode9专业技术文章分享
- 2024-06-28易优新手必读安装教程-icode9专业技术文章分享
- 2024-06-28忘记eyoucms后台密码怎么办?-icode9专业技术文章分享
- 2024-06-26终极指南:Scrum中如何设置需求优先级
- 2024-06-26AI大模型企业应用实战(25)-为Langchain Agent添加记忆功能
- 2024-06-26小白家庭 nas 搭建方案-icode9专业技术文章分享
- 2024-06-23AI大模型企业应用实战(14)-langchain的Embedding