【发布时间】:2019-08-20 10:58:28
【问题描述】:
请找到Activity xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@color/white"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_10ssp"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_menu"
android:layout_width="@dimen/_15sdp"
android:layout_height="@dimen/_15sdp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginStart="@dimen/_10sdp"
android:background="@drawable/ic_menu"
android:visibility="visible"
/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/mediumTextInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/text"
android:textColor="@color/colorPrimary"
android:textSize="@dimen/_14ssp" />
<com.suke.widget.SwitchButton
android:id="@+id/sb_private"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/_10sdp"
app:sb_background="@color/light3"
app:sb_checked="false"
app:sb_checked_color="@color/colorPrimary"
app:sb_checkline_color="@color/colorPrimary"
app:sb_show_indicator="false"
app:sb_uncheck_color="@color/light3"
app:sb_uncheckcircle_color="@color/white"
/>
</RelativeLayout>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
<FrameLayout
android:id="@+id/fl_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
</RelativeLayout>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/layout_nav_header"
app:menu="@menu/activity_main_drawer"
android:background="@color/white"
android:visibility="visible"
/>
这是我的子片段 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".fragment.MapFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="@dimen/_30sdp"
android:layout_height="@dimen/_30sdp"
android:id="@+id/iv_my_location"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/_20sdp"
android:layout_marginEnd="@dimen/_20sdp"
app:srcCompat="@drawable/ic_my_location_light4_with_background"
android:visibility="gone"
/>
</RelativeLayout>
</FrameLayout>
我在子片段中显示地图,我需要在地图的顶部位置显示工具栏,(工具栏背景应该对地图透明)
但是,子片段隐藏了工具栏,如何将这个工具栏带入地图中?工具栏对所有 Fragment 都是通用的。
我的要求是,“地图应该占据整个页面,它不应该低于工具栏,那是我在Framelayout中没有给出下面的布局
【问题讨论】:
-
你试过toolBar.bringToFront()吗?
-
@Piyush,我忘了这个小点,谢谢
标签: android android-fragments android-toolbar android-framelayout