2016-05-10 84 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。其實它包含你添加的內容。 –