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);
    }
}
复制代码

 

posted on   Hello-World3  阅读(136)  评论(0编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
点击右上角即可分享
微信分享提示