Android4.2.2 Gallery2源码分析(2)——发现Gallery.java

来源:互联网 发布:企业宣传制作软件 编辑:程序博客网 时间:2024/04/30 15:18

上文中,main.xml是我直接提出来的,并没有说明是怎么找到它的,现在说明发现它的理由:

一般我们分析界面布局会用到hierarchyviewer这个工具,从工具中,我们对应到视图,最主要的视图id我们找到了"gl_root_view",这一点在上一节中有说明。在Source insight中搜索这个id,我们找到了layout/Gl_root_group.xml:

[html] view plaincopyprint?
  1. <merge xmlns:android="http://schemas.android.com/apk/res/android">  
  2.     <com.android.gallery3d.ui.GLRootView  
  3.             android:id="@+id/gl_root_view"  
  4.             android:layout_width="match_parent"  
  5.             android:layout_height="match_parent"/>  
  6.     <View android:id="@+id/gl_root_cover"  
  7.             android:layout_width="match_parent"  
  8.             android:layout_height="match_parent"  
[html] view plaincopyprint?
  1. ...  

注意到这个layout的根标签为<merge>,因此这个layout是由别的layout整合使用的,再次搜索这个layout,找到了Main.xml:

[html] view plaincopyprint?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.         android:id="@+id/gallery_root"  
  4.         android:orientation="vertical"  
  5.         android:layout_width="match_parent"  
  6.         android:layout_height="match_parent">  
  7.     <include layout="@layout/gl_root_group"/>  
  8.     <FrameLayout android:id="@+id/header"  
  9.             android:visibility="gone"  
  10.             android:layout_alignParentTop="true"  
  11.             android:layout_width="match_parent"  
  12.             android:layout_height="wrap_content"/>  
  13.     <FrameLayout android:id="@+id/footer"  
  14.             android:visibility="gone"  
  15.             android:layout_alignParentBottom="true"  
  16.             android:layout_alignParentLeft="true"  
  17.             android:layout_alignParentRight="true"  
  18.             android:layout_width="match_parent"  
  19.             android:layout_height="wrap_content"/>  
  20. </RelativeLayout>  

综合上节中用hierarchyviewer看到的界面布局,因此这个Main.xml就是Gallery的主视图入口,在Gallery工程中搜索调用这个Main.xml的Activity。找到了Gallery.java这个类,从名字上应该有所发觉,这个类有点像我们以往所见的ActivityMain.java。因此Gallery.java是这个布局所对应的activity。

我们先抛开GLRootView.java这个视图,先从activity入手分析一下Gallery.java这个类

原创粉丝点击