Android——UI(1) (activity window decor)

1. activity window decor 之间的关系

android里:
1个app里面有一个或多个window
1个activity里有1个decor
1个window有1个decor
1个decor有多个viewgroup/layout
viewgroup/layout中有多个view.

activity就是一组相对独立的功能,每个activity有个显示界面,界面显示在窗口上,所以有个窗口。

installDecor() //PhoneWindow.java
  mContentParent = generateLayout(mDecor);

Decor是个树状结构,DecorView是这个树的根节点。

2. Framelayout也是一个ViewGroup的派生类。

3. Decor的样式就是通过AndroidManifest.xml中“android:theme”域来指定的。

3. Decor的样式就是通过AndroidManifest.xml中“android:theme”域来指定的。
<application
    android:theme="@style/AppTheme"    通过它来指定的,可以选择其它的,eg:@android:style/XXXX 会自动有提示。可以逐个试验一下。
 ......
>

4 .打印Decor的树状关系Demo代码

public void printViewHierarchy(View parent, int level, int childidx){
    /*
     *   * DecorView child -1 (x, y), (w, h)
     *   ** FrameLayout child 0 (x, y), (w, h)
     *   *** TextView  child 0  (x, y), (w, h)
     *   ** FrameLayout child 1 (x, y), (w, h)
     *   *** Button   child 0   (x, y), (w, h)
     *   *** TextView  child 1  (x, y), (w, h)
     *   *** FrameLayout  child 2 (x, y), (w, h)
     */
    int i;
    String levelStr = "*";
    for (i = 0; i < level; i++)
        levelStr += "*";

    int[] positons = new int[2];
    parent.getLocationOnScreen(positons);

    Log.d(TAG, levelStr + " " + parent.getClass().getName() + " child " + childidx
            + " (" + positons[0] + ", " + positons[1] + "), ("+parent.getWidth()+", "
            +parent.getHeight()+")");

    if (parent instanceof ViewGroup){
        View child;
        ViewGroup root = (ViewGroup)parent;
        i = 0;
        while ((child = root.getChildAt(i)) != null){
            printViewHierarchy(child, level+1, i);
            i++;
        }
    }
}


class MyButtonListener implements View.OnClickListener {
    @Override
    public void onClick(View v) {
        View decorView = getWindow().getDecorView();
        printViewHierarchy(decorView, 0, -1);
    }
}

猜你喜欢

转载自www.cnblogs.com/hellokitty2/p/10884194.html
今日推荐