zoukankan      html  css  js  c++  java
  • 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);
        }
    }
  • 相关阅读:
    (转)基于C#的socket编程的TCP异步实现
    socket
    (转)抽象类、抽象属性、抽象方法
    (转)c# 互斥锁
    (转)C#连接OleDBConnection数据库的操作
    c# DLL封装并调用
    网络cmd命令
    (转)UCOSII在任务切换与出入中断时堆栈指针的使用
    app和bootloader跳转 MSP与PSP
    (转)stm32启动文件详解
  • 原文地址:https://www.cnblogs.com/hellokitty2/p/10884194.html
Copyright © 2011-2022 走看看