对于百度地图有时候需要自定义一些UI的显示,对于sdk自带效果需要做一定的改动来满足我们的需求。其实地图上的各种试图都是浮动在地图上的view,所以去掉view只需要设置为GONE,或者找到父View给remove掉。但是具体是那个view我们就是踩着石头过河了。这里我们就需要用到强大的debug模式去遍历查看view树,然后对其id进行分析,根据命名可以推测大概的控件,然后通过全局搜素去搜id,找到对饮的布局,根据布局做操作就更得心应手
官方默认效果如下
我们要做的是将红色框内的视图隐藏掉
- 去百度地图官网下载最新的导航demo,修改配置运行
- 找到
DemoGuideActivity
的onCreate
- 在
setContentView(view);
添加
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
.......
View view = mRouteGuideManager.onCreate(this, mOnNavigationListener,
null, params);
if (view != null) {
setContentView(view);
//隐藏底部菜单
findViewById(R.id.bnav_rg_toolbox_panel_container).setVisibility(View.GONE);
}
......
}
效果如下图:
思路分析
- debug定位控件
我们将断点打到根视图view的位置,然后进入导航界面如上图,可以看到mChildren
有两个子视图,我们copy对应的id去搜索,最终定位相关的layout.xml,会发现这些xml都是在onsdk_all.aar中,所以 切换目录视图到project点击External Libraries找到onsdk_all.aar如下:
通过id找布局
布局文件找到了我们就可以开展相应工作了,最终我们要操作的是nsdk_layout_rg_main_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<com.baidu.navisdk.ui.widget.RGRootViewFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:apps="http://schemas.android.com/apk/res-auto"
android:id="@+id/bnav_rg_mapmode_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 地图容器 -->
<FrameLayout
android:id="@+id/bnav_rg_map_content"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- 选点 -->
<ViewStub
android:id="@+id/bnav_rg_pp_layout_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout="@layout/nsdk_layout_rg_mapmode_main_sub_pp" />
<ViewStub
android:id="@+id/common_debug_viewstub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout="@layout/nsdk_layout_rg_mapmode_main_sub_common_debug" />
<!-- 商业活动容器 -->
<LinearLayout
android:id="@+id/module_contains"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:visibility="gone"></LinearLayout>
<LinearLayout
android:id="@+id/bnav_rg_content_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/navi_dimens_0dp"
android:orientation="vertical"
android:padding="@dimen/navi_dimens_0dp">
<include layout="@layout/bnav_statusbar_empty_view_include" />
<!-- 顶部面板容器 -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--小度语音态-->
<ViewStub
android:id="@+id/bnav_rg_xd_voice_container_stub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/nsdk_rg_panel_margin_top"
android:inflatedId="@+id/bnav_rg_xd_voice_container"
android:layout="@layout/nsdk_layout_rg_xd_voice_panel"
android:visibility="gone" />
<!-- 诱导面板 -->
<LinearLayout
android:id="@+id/bnav_rg_top_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/nsdk_rg_panel_margin_top"
android:orientation="vertical"
android:visibility="visible">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- 模糊诱导信息 -->
<ViewStub
android:id="@+id/nsdk_layout_rg_mapmode_main_sub_fuzzy_guide_stub"
android:layout_width="match_parent"
android:layout_height="@dimen/nsdk_rg_top_panel_height"
android:inflatedId="@+id/nsdk_layout_rg_mapmode_main_sub_fuzzy_guide_panel"
android:layout="@layout/nsdk_layout_rg_mapmode_main_sub_fuzzy_guide" />
<!-- 简易诱导信息 -->
<include layout="@layout/nsdk_layout_rg_mapmode_main_sub_simple_guide" />
<!-- 高速模式容器 v4.0 -->
<FrameLayout
android:id="@+id/bnav_rg_highway_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"></FrameLayout>
<!-- 导航中设备状态 -->
<FrameLayout
android:id="@+id/bnav_rg_device_status_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/navi_dimens_10dp"
android:visibility="gone">
</FrameLayout>
<!--随后转向标-->
<FrameLayout
android:id="@+id/bnav_rg_next_deriction_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"></FrameLayout>
</FrameLayout>
</LinearLayout>
</RelativeLayout>
<!-- 操作态、辅助诱导面板 -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/nsdk_rg_guide_panel_shadow_left">
<RelativeLayout
android:id="@+id/bnav_rg_assist_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<include layout="@layout/nsdk_layout_rg_mapmode_assist_panel_layout" />
</RelativeLayout>
<!-- 控制面板-操作态 -->
<ViewStub
android:id="@+id/bnav_rg_control_panel_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/nsdk_rg_control_panel_bottom_margin"
android:layout="@layout/nsdk_layout_rg_mapmode_main_sub_control_panel" />
<ViewStub
android:id="@+id/bnav_rg_nearby_search_stub"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/nsdk_rg_control_panel_bottom_margin"
android:layout="@layout/nsdk_layout_rg_nearby_search_filter_panel" />
</FrameLayout>
</LinearLayout>
<!--简约面板容器-->
<RelativeLayout
android:id="@+id/bnav_simple_model_guide_panel_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.baidu.navisdk.ui.widget.EmptyTopLayout
android:id="@+id/bnav_simple_mode_guide_top_empty_view"
android:layout_width="@dimen/nsdk_rg_simple_model_guide_panel_width"
android:layout_height="wrap_content"/>
<!-- 简易模式诱导面板 -->
<ViewStub
android:id="@+id/bnav_rg_simple_mode_guide_stub"
android:layout_width="@dimen/nsdk_rg_simple_model_guide_panel_width"
android:layout_height="@dimen/nsdk_rg_simple_model_guide_panel_height"
android:layout_below="@id/bnav_simple_mode_guide_top_empty_view"
android:layout_marginTop="@dimen/nsdk_rg_panel_margin_top"
android:inflatedId="@+id/bnav_rg_simple_model_guide_panel"
android:layout="@layout/nsdk_layout_rg_simple_mode_guide" />
<!-- 简易模式高速诱导面板 -->
<ViewStub
android:id="@+id/bnav_rg_simple_mode_highway_view_stub"
android:layout_width="@dimen/nsdk_rg_simple_model_guide_panel_width"
android:layout_height="@dimen/nsdk_rg_simple_model_guide_panel_height"
android:layout_below="@id/bnav_simple_mode_guide_top_empty_view"
android:layout_marginTop="@dimen/nsdk_rg_panel_margin_top"
android:inflatedId="@+id/bnav_rg_simple_model_highway_view"
android:layout="@layout/nsdk_layout_rg_simple_mode_guide" />
</RelativeLayout>
<!--当前道路名view-->
<RelativeLayout
android:id="@+id/bnav_rg_cur_road_name_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<!--首汽view-->
<RelativeLayout
android:id="@+id/shouqi_view_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/nsdk_rg_toolbox_margin_left"
android:layout_marginBottom="@dimen/nsdk_rg_shouqi_view_bottom_margin"
android:layout_gravity="bottom" />
<!-- 工具箱 -->
<RelativeLayout
android:id="@+id/bnav_rg_toolbox_panel_container"
tools:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"/>
<!-- 菜单view -->
<RelativeLayout
android:id="@+id/bnav_rg_menu_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66000000"
android:visibility="gone">
<LinearLayout
android:id="@+id/bnav_rg_menu_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"/>
</RelativeLayout>
<!--ugc 上报面板-->
<com.baidu.navisdk.module.ugc.report.ui.UgcReportPanelLayout
android:id="@+id/bnav_rg_ugc_menu_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<!-- UGC 详情view -->
<include layout="@layout/nsdk_layout_ugc_detail_panel"/>
<!-- 周边搜索view -->
<RelativeLayout
android:id="@+id/bnav_rg_route_search_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66000000"
android:visibility="gone">
<RelativeLayout
android:id="@+id/bnav_rg_route_search_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<!-- 路线排序 -->
<LinearLayout
android:id="@+id/bnav_rg_route_sort_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/nsdk_cl_rg_bg_a"
android:orientation="vertical"
android:visibility="gone">
<View
android:layout_width="match_parent"
android:layout_height="@dimen/navi_dimens_0dp"
android:layout_weight="1" />
<RelativeLayout
android:id="@+id/bnav_rg_route_sort_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"></RelativeLayout>
</LinearLayout>
<!-- 放大图 -->
<ViewStub
android:id="@+id/bnav_rg_enlarge_road_map_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout="@layout/nsdk_layout_rg_mapmode_main_sub_enlarge_road_map" />
<RelativeLayout
android:id="@+id/bnav_rg_collada_view_rl"
android:layout_width="match_parent"
android:layout_height="@dimen/navi_dimens_200dp"
android:visibility="gone">
<LinearLayout
android:id="@+id/bnav_rg_collada_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:orientation="horizontal"></LinearLayout>
<ImageView
android:id="@+id/bnav_rg_collada_open_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/navi_dimens_0dp"
android:paddingBottom="@dimen/navi_dimens_0dp"
android:scaleType="centerInside"
android:src="@drawable/nsdk_drawable_enlarge_close_p"
android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/enlarge_lane_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:visibility="gone" />
<!--卡片容器-->
<RelativeLayout
android:id="@+id/navi_rg_card_container"
tools:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"></RelativeLayout>
<!-- 更多设置 -->
<RelativeLayout
android:id="@+id/bnav_rg_menu_more_setting_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"></RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bluetooth_panel_layout"
android:background="@color/nsdk_cl_rg_bg_a"
android:padding="@dimen/nsdk_rg_toolbox_margin_left"
android:visibility="gone" >
<!--蓝牙控制panel-->
<include layout="@layout/nsdk_layout_rg_bluetooth_controller_panel" />
</LinearLayout>
<RelativeLayout
android:id="@+id/navi_rg_safety_guide"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/nsdk_share_route_bg"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/navi_dimens_206dp"
android:text="@string/nsdk_string_rg_cp_safety_guide"
android:textColor="#ffffff"
android:textSize="@dimen/navi_dimens_19dp" />
</RelativeLayout>
<ViewStub
android:id="@+id/bnav_rg_notification_debug_layout_stub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/nsdk_layout_rg_mapmode_main_sub_notification_debug" />
<!-- 通知 -->
<RelativeLayout
android:id="@+id/bnav_rg_notification_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<RelativeLayout
android:id="@+id/bnav_rg_notification_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"></RelativeLayout>
</RelativeLayout>
<!--高速订阅面板-->
<ViewStub
android:id="@+id/navi_rg_highway_subscript_stub"
android:inflatedId="@+id/navi_rg_highway_subscript_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout="@layout/nsdk_layout_hw_subscript_view"
android:visibility="gone"/>
<ViewStub
android:id="@+id/open_the_door_for_me"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout="@layout/nsdk_layout_rg_mapmode_main_sub_open_the_door" />
<FrameLayout
android:id="@+id/debug_view_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:visibility="gone">
</FrameLayout>
<!--首次引导-->
<RelativeLayout
android:id="@+id/navi_rg_first_enter_guide"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"></RelativeLayout>
</com.baidu.navisdk.ui.widget.RGRootViewFrameLayout>
去修改布局文件是可以达到我们效果,但是不是很灵活,而且一般般的aar是只读文件,所以还是在代码中实现比较好。
所以要想干掉对应的布局只需要在上面的布局文件中找id,然后设置GONE;比较人性化的是还提供了相关控件的注释,举一反三