标签:
界面的展示部分:------->界面的加载(Activity、Window、View之间的关系)|
1
2
3
4
5
|
@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.xxxx);} |
|
1
2
3
4
5
6
7
8
9
|
public void setContentView(int layoutResID) { getWindow().setContentView(layoutResID);}public void setContentView(View view) { getWindow().setContentView(view);}public void setContentView(View view, ViewGroup.LayoutParams params) { getWindow().setContentView(view, params);} |
|
1
2
3
4
5
6
|
final void attach(.......) { ... //创建一个Window对象 mWindow = PolicyManager.makeNewWindow(this); ....} |
|
1
2
3
4
5
6
|
public final class PolicyManager { private static final IPolicy sPolicy; public static Window makeNewWindow(Context context) { return sPolicy.makeNewWindow(context); }} |
|
1
2
3
|
public PhoneWindow makeNewWindow(Context context) { return new PhoneWindow(context);} |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
public class PhoneWindow extends Window implements MenuBuilder.Callback { private DecorView mDecor; private ViewGroup mContentParent; private LayoutInflater mLayoutInflater; //DecorView其实就是Window中View的RootView private final class DecorView extends FrameLayout implements RootViewSurfaceTaker { } @Override public void setContentView(int layoutResID) { if (mContentParent == null) { //没看懂,可以理解为让mDecor和mContentParent产生了关系 //其实就是把View放在RootView上 installDecor(); } else { mContentParent.removeAllViews(); } mLayoutInflater.inflate(layoutResID, mContentParent); final Callback cb = getCallback(); if (cb != null) { cb.onContentChanged(); } } private void installDecor() { if (mDecor == null) { mDecor = generateDecor(); mDecor.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); mDecor.setIsRootNamespace(true); } if (mContentParent == null) { mContentParent = generateLayout(mDecor); ..... .... } }} |
标签:
原文地址:http://blog.csdn.net/kkopopo/article/details/42126691