Android DecorView浅析
来源:互联网 发布:sql基础语法 编辑:程序博客网 时间:2024/05/19 00:41
Android DecorView浅析
Posted on 2012-07-13 10:26 曙光城邦 阅读(2430) 评论(0) 编辑 收藏一、DecorView为整个Window界面的最顶层View。
二、DecorView只有一个子元素为LinearLayout。代表整个Window界面,包含通知栏,标题栏,内容显示栏三块区域。
三、LinearLayout里有两个FrameLayout子元素。
(20)为标题栏显示界面。只有一个TextView显示应用的名称。也可以自定义标题栏,载入后的自定义标题栏View将加入FrameLayout中。
(21)为内容栏显示界面。就是setContentView()方法载入的布局界面,加入其中。
工具查看:
1.
下图为SDK中tools文件夹下hierarchyviewer bat 查看ViewTree的结果:
(此时未替换标题栏)
2.替换标题栏后ViewTree的变化:
绿色区域发生了变化,改变为了载入的title.xml文件的布局。
title.xml内容为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/title_tv"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:text="@string/app_name"
/>
</LinearLayout>
通知栏绘制在1号LinearLayout中,还是绘制在DecorView中还有待探究。
-----------------
ApiDemo中app包下CustomTitle中自定义TitleBar代码段
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
载入自定义titleBar后如何查找其中元素呢,其实还是findViewById就可以了,因为载入的自定义布局已经在DecorView树中了
而findViewById是怎么回事呢。
activity中findViewById源码
public View findViewById(int id) {
return getWindow().findViewById(id);
}
调用了getWindow().findViewById,getWindow返回的是Window点入查看window中源码
public View findViewById(int id) {
return getDecorView().findViewById(id);
}
所以最终是从DecorView最顶层开始搜索的。
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- android DecorView 浅析
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- Android DecorView浅析
- unix 网路编程(卷一)第一个程序编译过程unix网络编程 第一个例子 connect error: Connection refused
- voilate详解
- 试一试-自定义数据类型
- ABAP里面的面对对象设计
- 第十五周 多科成绩单
- Android DecorView浅析
- 对stackt中的每一个对象调用某个方法,stackt采用模板进行定义
- Java编程中“为了性能”尽量要做的26点
- PostThreadMessage实现多线程间消息通信
- Top 10 JDBC Best Practices for Java Programmer Read more: http://javarevisited.blogspot.com/2012/08
- 【javascript】动态管理用户
- 百度笔试题:绳子最多覆盖多少个点
- 关于解决ubuntu误改sudoers文件的解决办法
- android屏幕旋转时,Activity不重新调用onCreate的方法