您的位置:首页 > 移动开发 > Android开发

[RK3288][Android7.1.2] Launcher3 源码阅读之step5:查看主要的xml布局文件

2017-08-16 14:59 627 查看
launcher.xml文件是需要我们Launcher.java的主要布局。

统计了一下,以“<com.”开头的View有16处,所以我们大约估计它有16+个自定义VIew

详细注解如下:

path:rk3288\packages\apps\Launcher3\res\layout-land\launcher.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Full screen view projects under the status bar and contains the background -->
<!-- LauncherRootView 继承了 FrameLayout 类-->
<!-- DragLayer 继承了 FrameLayout 类-->
<!--所以:LauncherRootView 与 DragLayer 是同一级别的。-->
<com.android.launcher3.LauncherRootView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res-auto"
android:id="@+id/launcher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<com.android.launcher3.dragndrop.DragLayer
android:id="@+id/drag_layer"
android:clipChildren="false"
android:clipToPadding="false"
android:background="@drawable/workspace_bg"
android:importantForAccessibility="no"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- The workspace contains 5 screens of cells -->
<!-- DO NOT CHANGE THE ID -->
<!-- Workspace 继承的是 PagedView-->
<!-- PagedView 继承的是 ViewGroup-->
<!-- Workspace 的特性受制于PagedView -->
<!-- 看自定义View的时候,需要多关注 PagedView 的实现和特性 -->
<com.android.launcher3.Workspace
android:id="@+id/workspace"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
launcher:pageIndicator="@id/page_indicator" />

<!-- DO NOT CHANGE THE ID -->
<!-- 这里用include 方式引用了 hotseat 的布局,方便阅读,具体要去看hotseat 的xml文件 -->
<include
android:id="@+id/hotseat"
layout="@layout/hotseat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
launcher:layout_ignoreInsets="true" />

<!-- 同理 hotseat ,需要查看的是 drop_target_bar.xml文件-->
<include
android:id="@+id/drop_target_bar"
layout="@layout/drop_target_bar_vert" />

<!-- 同理 hotseat ,需要查看的是 overview_panel.xml文件,但是这里默认是隐藏的 visibility =gone -->
<include
android:id="@+id/overview_panel"
layout="@layout/overview_panel"
android:visibility="gone" />

<!-- dynamic_grid_page_indicator_height =28dp -->
<!-- PageIndicatorCaretLandscape 继承的是 PageIndicator -->
<!-- PageIndicator 继承的是 FrameLayout -->
<com.android.launcher3.pageindicators.PageIndicatorCaretLandscape
android:id="@+id/page_indicator"
android:layout_width="@dimen/dynamic_grid_page_indicator_height"
android:layout_height="@dimen/dynamic_grid_page_indicator_height"
android:layout_gravity="center|bottom"
android:layout_marginBottom="30dp"/>

<!-- A place holder view instead of the QSB in transposed layout -->
<View
android:id="@+id/workspace_blocked_row"
android:layout_width="0dp"
android:layout_height="10dp"/>

<!-- 同理 hotseat ,需要查看的是 widgets_view.xml文件-->
<include
android:id="@+id/widgets_view"
layout="@layout/widgets_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />

<!-- 同理 hotseat ,需要查看的是 apps_view.xml文件-->
<include
android:id="@+id/apps_view"
layout="@layout/all_apps"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />

</com.android.launcher3.dragndrop.DragLayer>

</com.android.launcher3.LauncherRootView>

path:rk3288\packages\apps\Launcher3\res\layout\hotseat.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Hotseat 类继承于 FrameLayout-->
<com.android.launcher3.Hotseat
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res-auto">
<!-- CellLayout 类继承于 ViewGroup-->
<com.android.launcher3.CellLayout
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center" />
</com.android.launcher3.Hotseat>

rk3288\packages\apps\Launcher3\res\layout\drop_target_bar_vert.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- DropTargetBar 类继承于 LinearLayout-->
<!-- 里面放的布局是:水平还是垂直?-->
<!-- orientation = vertical -->
<!-- ______________________ -->
<!-- ______________________ -->
<!-- ______________________ -->
<com.android.launcher3.DropTargetBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/dynamic_grid_drop_target_size"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_gravity="left"
android:focusable="false"
android:paddingTop="@dimen/vert_drop_target_vertical_gap" >

<!-- Delete target -->
<!-- DeleteDropTarget 继承了 ButtonDropTarget -->
<!-- ButtonDropTarget 继承了 TextView -->
<com.android.launcher3.DeleteDropTarget
android:layout_width="match_parent"
android:layout_height="@dimen/dynamic_grid_drop_target_size"
android:gravity="center"
android:paddingLeft="@dimen/vert_drop_target_horizontal_gap"
android:paddingRight="@dimen/vert_drop_target_horizontal_gap"
android:id="@+id/delete_target_text"
android:textColor="@android:color/white" />

<!-- Uninstall target -->
<!-- UninstallDropTarget 继承了 ButtonDropTarget -->
<!-- ButtonDropTarget 继承了 TextView -->
<com.android.launcher3.UninstallDropTarget
android:layout_width="match_parent"
android:layout_height="@dimen/dynamic_grid_drop_target_size"
android:gravity="center"
android:paddingLeft="@dimen/vert_drop_target_horizontal_gap"
android:paddingRight="@dimen/vert_drop_target_horizontal_gap"
android:id="@+id/uninstall_target_text"
android:textColor="@android:color/white"
android:layout_marginTop="@dimen/vert_drop_target_vertical_gap"/>

<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

<!-- App Info -->
<!-- InfoDropTarget 继承了 UninstallDropTarget -->
<!-- UninstallDropTarget 继承了 ButtonDropTarget -->
<!-- ButtonDropTarget 继承了 TextView -->
<com.android.launcher3.InfoDropTarget
android:layout_width="match_parent"
android:layout_height="@dimen/dynamic_grid_drop_target_size"
android:gravity="center"
android:paddingLeft="@dimen/vert_drop_target_horizontal_gap"
android:paddingRight="@dimen/vert_drop_target_horizontal_gap"
android:id="@+id/info_target_text"
android:textColor="@android:color/white"
android:layout_marginBottom="64dp"/>

</com.android.launcher3.DropTargetBar>

path:rk3288\packages\apps\Launcher3\res\layout\overview_panel.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- orientation = horizontal -->
<!-- ||||||||||||||||||||||||||||| -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:gravity="top"
android:orientation="horizontal" >

<TextView
android:id="@+id/wallpaper_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="4dp"
android:drawableTop="@drawable/ic_wallpaper"
android:fontFamily="sans-serif-condensed"
android:gravity="center_horizontal"
android:stateListAnimator="@animator/overview_button_anim"
android:text="@string/wallpaper_button_text"
android:textAllCaps="true"
android:textColor="@android:color/white"
android:textSize="12sp" />

<TextView
android:id="@+id/widget_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="4dp"
android:drawableTop="@drawable/ic_widget"
android:fontFamily="sans-serif-condensed"
android:gravity="center_horizontal"
android:stateListAnimator="@animator/overview_button_anim"
android:text="@string/widget_button_text"
android:textAllCaps="true"
androi
c5e5
d:textColor="@android:color/white"
android:textSize="12sp" />

<TextView
android:id="@+id/settings_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="4dp"
android:drawableTop="@drawable/ic_setting"
android:fontFamily="sans-serif-condensed"
android:gravity="center_horizontal"
android:stateListAnimator="@animator/overview_button_anim"
android:text="@string/settings_button_text"
android:textAllCaps="true"
android:textColor="@android:color/white"
android:textSize="12sp" />

</LinearLayout>

path:rk3288\packages\apps\Launcher3\res\layout\widgets_view.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- WidgetsContainerView 继承 BaseContainerView -->
<!-- BaseContainerView 继承 FrameLayout -->
<com.android.launcher3.widget.WidgetsContainerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res-auto"
android:id="@+id/widgets_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="afterDescendants"
launcher:revealBackground="@drawable/quantum_panel_shape_dark"
android:theme="@style/WidgetContainerTheme">

<View
android:id="@+id/reveal_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:focusable="false"
android:elevation="2dp"
android:visibility="invisible" />

<FrameLayout
android:id="@+id/main_content"
android:layout_gravity="center"
android:elevation="15dp"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- WidgetsRecyclerView 继承 BaseRecyclerView -->
<!-- BaseRecyclerView 继承 RecyclerView -->
<com.android.launcher3.widget.WidgetsRecyclerView
android:id="@+id/widgets_list_view"
android:theme="@style/CustomOverscroll.Dark"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/loader"
android:layout_gravity="center" />
</FrameLayout>

</com.android.launcher3.widget.WidgetsContainerView>

path:rk3288\packages\apps\Launcher3\res\layout\all_apps.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- AllAppsContainerView 继承 BaseContainerView -->
<!-- BaseContainerView 继承 FrameLayout -->
<com.android.launcher3.allapps.AllAppsContainerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res-auto"
android:id="@+id/apps_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
launcher:revealBackground="@drawable/quantum_panel_shape">

<View
android:id="@+id/reveal_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:focusable="false"
android:visibility="invisible" />

<!-- AllAppsRecyclerViewContainerView 继承 FrameLayout -->
<com.android.launcher3.allapps.AllAppsRecyclerViewContainerView
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:focusable="true"
android:focusableInTouchMode="true"
android:saveEnabled="false"
android:visibility="gone">

<!-- DO NOT CHANGE THE ID -->
<!-- AllAppsRecyclerView 继承 BaseRecyclerView -->
<!-- AllAppsRecyclerView 继承 RecyclerView -->
<com.android.launcher3.allapps.AllAppsRecyclerView
android:id="@+id/apps_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|top"
android:layout_marginTop="@dimen/all_apps_search_bar_height"
android:clipToPadding="false"
android:descendantFocusability="afterDescendants"
android:focusable="true"
android:theme="@style/CustomOverscroll.Light" />

<FrameLayout
android:id="@+id/search_container"
android:layout_width="match_parent"
android:layout_height="@dimen/all_apps_search_bar_height"
android:layout_gravity="center|top"
android:paddingTop="@dimen/all_apps_search_bar_margin_top"
android:gravity="center|bottom"
android:orientation="horizontal"
android:saveEnabled="false">

<!-- ExtendedEditText 继承 EditText -->
<com.android.launcher3.ExtendedEditText
android:id="@+id/search_box_input"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:focusableInTouchMode="true"
android:gravity="center"
android:imeOptions="actionSearch|flagNoExtractUi"
android:inputType="text|textNoSuggestions|textCapWords"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#4c4c4c"
android:hint="@string/all_apps_search_bar_hint"
android:textColorHint="@drawable/all_apps_search_hint"
android:textSize="16sp" />
</FrameLayout>

</com.android.launcher3.allapps.AllAppsRecyclerViewContainerView>
<View
android:id="@+id/nav_bar_bg"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:background="@color/all_apps_navbar_color"
android:focusable="false"
android:visibility="invisible" />
</com.android.launcher3.allapps.AllAppsContainerView>


至此,我们可以根据包名+类名找到对应的自定义的实现部分.java文件。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息