In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to analyze the rendering process of Activity. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
# the following code is based on API25
How does 1.Activity unfold in front of us?
I probably know that the UI aspect is related to Window, and activity's attach method passes in a window object, so I'll start with activity's attach method:
A PhoneWindow is created in the attach method
Activity executes a method performCreateCommon when it executes the onCreate method
Click the setEnterActivityOptions method:
Notice the method window.getDecorView ()
/ * *
* Retrieve the top-level window decor view (containing the standard
* window frame/decorations and the client's content inside of that), which
* can be added as a window to the window manager.
*
*
Note that calling this function for the first time "locks in"
* various window characteristics as described in
* {@ link # setContentView (View, android.view.ViewGroup.LayoutParams)}
*
* @ return Returns the top-level window decor view.
, /
Public abstract View getDecorView ()
The official explanation is that this method gets the decorview of the top-level window.
The window here is obviously PhoneWindow. Look at its implementation of getDecorView.
MDecor is actually generated in the constructor of PhoneWindow.
PreservedWindow traces its source upwards:
In fact, you can't find the relevant source code for activity display from onCreate, so you can only see how others analyze it.
Https://www.aliyun.com/jiaocheng/6995.html (Daozhong key point)
Https://www.cnblogs.com/snow-flower/p/6111599.html
Https://blog.csdn.net/monkey646812329/article/details/52885835
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; / / Normally the ViewRoot sets up callbacks with the Activity / / in addView- > ViewRootImpl#setView. If we are instead reusing / / the decor view we have to notify the view root that the / / callbacks may have changed. ViewRootImpl impl = decor.getViewRootImpl (); if (impl! = null) {impl.notifyChildRebuilt ();}} if (a.mVisibleFromClient & &! a.mWindowAdded) {a.mWindowAdded = true; wm.addView (decor, l) } / / If the window has already been added, but during resume// we started another activity, then don't yet make the// window visible.} else if (! willBeVisible) {if (localLOGV) Slog.v (TAG, "Launch" + r + "mStartedActivity set"); r.hideForNow = true;}
Look at the source code above
Get the PhoneWindow object
R.window = r.activity.getWindow (); View decor = r.window.getDecorView ()
Get DecorView from PhoneWindow and assign it to activity
A.mDecor = decor
Add decor through WindowManager
Wm.addView (decor, l)
So activity is displayed in front of us. On the lower level of WindowManager source code after discussion.
SetContentView method of 2.Activity
/ * Set the activity content from a layout resource. The resource will be * inflated, adding all top-level views to the activity. * * @ param layoutResID Resource ID to be inflated. * * @ see # setContentView (android.view.View) * @ see # setContentView (android.view.View, android.view.ViewGroup.LayoutParams) * / public void setContentView (@ LayoutRes int layoutResID) {getWindow () .setContentView (layoutResID); initWindowDecorActionBar ();} / * Set the activity content to an explicit view. This view is placed * directly into the activity's view hierarchy. It can itself be a complex * view hierarchy. When calling this method, the layout parameters of the * specified view are ignored. Both the width and the height of the view are * set by default to {@ link ViewGroup.LayoutParams#MATCH_PARENT}. To use * your own layout parameters, invoke * {@ link # setContentView (android.view.View, android.view.ViewGroup.LayoutParams)} * instead. * * @ param view The desired content to display. * * @ see # setContentView (int) * @ see # setContentView (android.view.View, android.view.ViewGroup.LayoutParams) * / public void setContentView (View view) {getWindow () .setContentView (view); initWindowDecorActionBar ();} / * Set the activity content to an explicit view. This view is placed * directly into the activity's view hierarchy. It can itself be a complex * view hierarchy. * * @ param view The desired content to display. * @ param params Layout parameters for the view. * * @ see # setContentView (android.view.View) * @ see # setContentView (int) * / public void setContentView (View view, ViewGroup.LayoutParams params) {getWindow (). SetContentView (view, params); initWindowDecorActionBar ();} / * * Add an additional content view to the activity. Added after any existing * ones in the activity-existing views are NOT removed. * * @ param view The desired content to display. * @ param params Layout parameters for the view. * / public void addContentView (View view, ViewGroup.LayoutParams params) {getWindow () .addContentView (view, params); initWindowDecorActionBar ();}
There are four ways to populate view,activity. Let's first discuss the most commonly used methods.
Public void setContentView (@ LayoutRes int layoutResID) {getWindow () .setContentView (layoutResID); initWindowDecorActionBar ();}
The first step is to call the corresponding method of PhoneWindow (if you look at the source code, you will find that most of the methods of activity are operating PhoneWindow)
Step 2 initialize ActionBar
First take a look at the source code of PhoneWindow
Overridepublic void setContentView (int layoutResID) {/ / Note: FEATURE_CONTENT_TRANSITIONS may be set in the process of installing the window / / decor, when theme attributes and the like are crystalized. Do not check the feature / / before this happens. If (mContentParent = = null) {installDecor ();} else if (! hasFeature (FEATURE_CONTENT_TRANSITIONS)) {mContentParent.removeAllViews ();} if (hasFeature (FEATURE_CONTENT_TRANSITIONS)) {final Scene newScene = Scene.getSceneForLayout (mContentParent, layoutResID, getContext ()); transitionTo (newScene);} else {mLayoutInflater.inflate (layoutResID, mContentParent);} mContentParent.requestApplyInsets () Final Callback cb = getCallback (); if (cb! = null & &! isDestroyed ()) {cb.onContentChanged ();} mContentParentExplicitlySet = true;}
At the beginning, the program should follow the installDecor method.
This method is relatively long, it is responsible for the following main business.
If decor is null, create a decor for PhoneWindow, and decor is bound to PhoneWindow if it already exists.
If mContentParent is null, create a mContentParent through decor.
The handling of transition Animation
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); / / Set up decor part of UI to ignore fitsSystemWindows if appropriate. MDecor.makeOptionalFitsSystemWindows (); final DecorContentParent decorContentParent = (DecorContentParent) mDecor.findViewById (R.id.decor_content_parent); if (decorContentParent! = null) {mDecorContentParent = decorContentParent; mDecorContentParent.setWindowCallback (getCallback ()); if (mDecorContentParent.getTitle () = = null) {mDecorContentParent.setWindowTitle (mTitle);} final int localFeatures = getLocalFeatures () For (int I = 0; I < FEATURE_MAX; iTunes +) {if ((localFeatures & (1 = android.os.Build.VERSION_CODES.HONEYCOMB) {if (a.getBoolean (R.styleable.Window_windowCloseOnTouchOutside, false)) {setCloseOnTouchOutsideIfNotSet (true)) }} if (! hasSoftInputMode ()) {params.softInputMode = a.getInt (R.styleable.Window_windowSoftInputMode, params.softInputMode) } if (a.getBoolean (R.styleable.Window_backgroundDimEnabled, mIsFloating)) {/ * All dialogs should have the window dimmed * / if ((getForcedWindowFlags () & WindowManager.LayoutParams.FLAG_DIM_BEHIND) = = 0) {params.flags | = WindowManager.LayoutParams.FLAG_DIM_BEHIND } if (! haveDimAmount ()) {params.dimAmount = a.getFloat (android.R.styleable.Window_backgroundDimAmount, 0.5f);}} if (params.windowAnimations = = 0) {params.windowAnimations = a.getResourceId (R.styleable.Window_windowAnimationStyle, 0);} / / The rest are only done if this window is not embedded Otherwise, / / the values are inherited from our container. If (getContainer () = = null) {if (mBackgroundDrawable = = null) {if (mBackgroundResource = = 0) {mBackgroundResource = a.getResourceId (R.styleable.Window_windowBackground, 0);} if (mFrameResource = = 0) {mFrameResource = a.getResourceId (R.styleable.Window_windowFrame, 0) } mBackgroundFallbackResource = a.getResourceId (R.styleable.Window_windowBackgroundFallback, 0); if (false) {System.out.println ("Background:" + Integer.toHexString (mBackgroundResource) + "Frame:" + Integer.toHexString (mFrameResource)) } if (mLoadElevation) {mElevation = a.getDimension (R.styleable.Window_windowElevation, 0);} mClipToOutline = a.getBoolean (R.styleable.Window_windowClipToOutline, false); mTextColor = a.getColor (R.styleable.Window_textColor, Color.TRANSPARENT);} / / Inflate the window decor. Int layoutResource; int features = getLocalFeatures (); / / System.out.println ("Features: 0x" + Integer.toHexString (features)); if ((features & (1)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.