2015-02-05 51 views
1

对于我的生活,我无法得到这个Toolbar布局顶部(注意:不在上面,但最重要的)其兄弟LinearLayout。我可以通过Toolbar覆盖其兄弟的唯一方法是将Toolbar的标高指定为> 0,但这对于5.0之前版本不起作用。如何让工具栏覆盖兄弟的布局(z排序)

我正在使用父项FrameLayout,而子项Toolbar位于XML的兄弟LinearLayout之后。我错过了什么?即使是Android Studio中预览窗格显示Toolbar上的LinearLayout

顶部

enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     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" 
     android:id="@+id/fragment_main_container" 
     tools:context=".MainActivity" 
     tools:ignore="MergeRootFrame" 
     android:orientation="vertical" 
     > 
     <FrameLayout 
      android:layout_weight="4" 
      android:layout_width="match_parent" 
      android:layout_height="0dp"> 
      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:src="@drawable/ic_launcher" 
       /> 
     </FrameLayout> 
     <ListView 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="5" 
      android:id="@+id/home_list_listview" 
      android:drawSelectorOnTop="true" 
      android:divider="@null" 
      android:dividerHeight="0dp" 
      tools:listitem="@layout/home_list_item" 
      > 
     </ListView> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:text="@string/slogan" 
      android:gravity="center" 
      android:textColor="@color/colorPrimaryDark" 
      /> 
    </LinearLayout> 

    <android.support.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="?attr/actionBarSize" 
     android:background="@android:color/transparent" 
     /> 
</FrameLayout> 

回答

0

结果我发现我犯了主要活动的线性布局,这已经包含这一个片段。哎呀!

0

这是因为FrameLayout。 如果你想使用FrameLayout,视图将不会相互关联。 因此,所有你需要做的是...

set "height of toolbar" to MarginTop of LinearLayout. 

希望,它将帮助。