2016-05-10 45 views
0

我的haha.xml布局被android.support.design.widget.AppBarLayout覆盖,我怎样才能让haha.xml上的按钮出现在AppBarLayout下? enter image description hereLinearLayout被AppBarLayout覆盖

haha​​.xml布局

enter image description here

PS: activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.example.william.test.MainActivity" 
    tools:showIn="@layout/activity_main"> 
    <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/AppTheme.AppBarOverlay"> 

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

     </android.support.design.widget.AppBarLayout> 
     <include layout="@layout/haha" /> 
</android.support.design.widget.CoordinatorLayout> 

haha​​.xml

<?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" 
    android:background="@color/red"> 
    <Button 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:text="按钮不可用1"/> 

</LinearLayout> 
+0

你周围似乎没有围绕AppBarLayout + LinearLayout的布局 –

+0

@ cricket_007更新了activity_main.xml包含的全部内容。 –

回答

0

包装你AppBarLayouthaha layoutLayoutManager安排UI元素
例如,你可以使用LinearLayout

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
...> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/AppTheme.AppBarOverlay"> 

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

     </android.support.design.widget.AppBarLayout> 
     <include layout="@layout/haha" /> 
    </LinearLayout> 
</android.support.design.widget.CoordinatorLayout> 

希望这有助于

0

尝试以下操作:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.fragments.myapplication.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 
     <include layout="@layout/haha" /> 
    </android.support.design.widget.AppBarLayout> 
    </android.support.design.widget.CoordinatorLayout> 
+0

谢谢。我更新了activity_main.xml。其实它包含你添加的内容。 –