2016-09-01 63 views
-2

我有一個AppCompatActivity,我有一個工具欄和谷歌地圖片段。這是用XML製作的:工具欄裏面的片段重疊片段

<?xml version="1.0" encoding="utf-8"?> 
<fragment 
class="com.google.android.gms.maps.SupportMapFragment" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/map" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbarFindRoutes" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    android:theme="@style/AppTheme.AppBarOverlay" 
    app:popupTheme="@style/AppTheme.PopupOverlay"/> 


</fragment> 

但是,我的工具欄位於我的片段視圖之上。我想要在工具欄下面有片段,但據我所知,我需要將片段作爲XML中的根元素。這意味着我不能有一個RelativeLayout作爲根,並且在工具欄下面聲明片段。

+0

你應該把它放在裏面'框架Layout'。 –

回答

1

更改您的佈局如下

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical"> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbarFindRoutes" 
     app:popupTheme="@style/AppTheme.PopupOverlay" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     android:elevation="4dp" 
     android:theme="@style/AppTheme.AppBarOverlay" /> 

    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/map" 
     class="com.robo.movie.movieapp.Movies.ui.MovieListFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

</LinearLayout>