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

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

<merge xmlns:android="http://schemas.android.com/apk/res/android">
<com.android.gallery3d.ui.GLRootView
android:id="@+id/gl_root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View android:id="@+id/gl_root_cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
...

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

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gallery_root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/gl_root_group"/>
<FrameLayout android:id="@+id/header"
android:visibility="gone"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout android:id="@+id/footer"
android:visibility="gone"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>

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

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

Android4.2.2 Gallery2源码分析(2)——发现Gallery.java的更多相关文章

  1. Android4.2.2 Gallery2源码分析(4)——GLCanvas.java

    首先申明,找到这个类是在GLRootView.java中发现的线索.这是一个接口,源码中对该接口作了详细的说明: // // GLCanvas gives a convenient interface ...

  2. Android4.2.2 Gallery2源码分析(5)——GLCanvasImpl.java

    GLCanvasImpl.java是接口GLCanvas的唯一实现类,也就是说二者在功能上完全等同.代码中调用GLCanvas对象函数的地方,等效于调用GLCanvasImpl中的该函数,GLCanv ...

  3. Android 7.0 Gallery图库源码分析1 - 初识Gallery源码

    分析一个项目的源代码时,第一件事就是查看清单文件,找到程序入口,我们从Gallery2源码的清单文件中可以看到GalleryActivity是此应用的启动Activity. <activity ...

  4. jQuery1.6源码分析系列

    原文地址:http://www.cnblogs.com/nuysoft/archive/2011/11/14/2248023.html jQuery源码分析(版本1.6.1) 目录 00 前言开光 0 ...

  5. STL 源码分析《1》---- list 归并排序的 迭代版本, 神奇的 STL list sort

    最近在看 侯捷的 STL源码分析,发现了以下的这个list 排序算法,乍眼看去,实在难以看出它是归并排序. 平常大家写归并排序,通常写的是 递归版本..为了效率的考虑,STL库 给出了如下的 归并排序 ...

  6. ScheduleThreadPoolExecutor源码分析

    ScheduleThreadPoolExecutor源码分析(一) Java中ScheduleThreadPoolExecutor主要用于执行延迟任务或者按照一定的频率执行任务.其中scheduleA ...

  7. JDK1.7源码分析01-Collection

    同步发布:http://www.yuanrengu.com/index.php/20180221.html Java的集合类主要由两个接口派生而出:Collection和Map.Collection是 ...

  8. AbstractQueuedSynchronizer源码分析

    AbstractQueuedSynchronizer源码分析 前提 AQS(java.util.concurrent.locks.AbstractQueuedSynchronizer)是并发编程大师D ...

  9. ArrayList相关方法介绍及源码分析

    目录 ArrayList简介: ArrayList 相关方法介绍 代码表示 相关方法源码分析 ArrayList简介: java.util.ArrayList 是我们最常用的一个类,ArrayList ...

随机推荐

  1. PHP获取以为数组中的最大值和最小值

    1.PHP获取一维数组中的最大值 <?php $a=array('1','3','55','99'); $pos = array_search(max($a), $a); echo $a[$po ...

  2. NumPy 新知

    import numpy as np a = np.arange(5) a array([0, 1, 2, 3, 4]) 增加一个维度: b = a[:, None] c = a[:,np.newax ...

  3. 「TJOI 2018」游园会 Party

    「TJOI 2018」游园会 Party 题目描述 小豆参加了 \(NOI\) 的游园会,会场上每完成一个项目就会获得一个奖章,奖章只会是 \(N, O, I\) 的字样. 在会场上他收集到了 \(K ...

  4. [APIO2018]铁人两项 --- 圆方树

     [APIO2018] 铁人两项 题目大意: 给定一张图,问有多少三元组(a,b,c)(a,b,c 互不相等)满足存在一条点不重复的以a为起点,经过b,终点为c的路径 如果你不会圆方树 ------- ...

  5. [BZOJ4651][NOI2016]网格(Tarjan)

    下面直接给出结论,相关证明见官方题解. 1.若跳蚤数不超过1或仅有两只跳蚤且相邻,则答案为-1. 2.若跳蚤形成的连通块个数大于1,则答案为0. 3.若跳蚤之间建图存在割点,则答案为1. 4.否则为2 ...

  6. [BZOJ3514]CodeChef MARCH14 GERALD07加强版(LCT+主席树)

    3514: Codechef MARCH14 GERALD07加强版 Time Limit: 60 Sec  Memory Limit: 256 MBSubmit: 2177  Solved: 834 ...

  7. HDU 5575 Discover Water Tank 并查集 树形DP

    题意: 有一个水槽,边界的两块板是无穷高的,中间有n-1块隔板(有高度),现有一些条件(i,y,k),表示从左到右数的第i列中,在高度为(y+0.5)的地方是否有水(有水:k = 1),问最多能同时满 ...

  8. Educational Codeforces Round 12 D. Simple Subset 最大团

    D. Simple Subset 题目连接: http://www.codeforces.com/contest/665/problem/D Description A tuple of positi ...

  9. CROC 2016 - Qualification C. Hostname Aliases map

    C. Hostname Aliases 题目连接: http://www.codeforces.com/contest/644/problem/C Description There are some ...

  10. Codeforces Round #300 D. Weird Chess 水题

    D. Weird Chess Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/proble ...