2017-02-27 25 views
2

我有一個應用程序佈局,自定義toolbar和持久BottomSheet - 都在CoordinatorLayout內。我想要顯示BottomSheet。此時表單全屏顯示並覆蓋toolbar。通過將應用程序主題設置爲保持低於ActionBar,但酒吧不能定製。ActionBar下面的持久底片

有沒有一種方法來限制persit的高度BottomSheet爲全屏 - ActionBar高度?

這是我在activity_main.xml

<android.support.design.widget.CoordinatorLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:attrs="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.test.MainActivity"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     app:elevation="20dp" 
     android:elevation="20dp" 
     android:layout_height="?attr/actionBarSize"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      app:elevation="20dp" 
      android:elevation="20dp" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary"/> 
    </android.support.design.widget.AppBarLayout> 
    </LinearLayout> 
    <include layout="@layout/bottom_sheet_additem"/> 
</CoordinatorLayout> 

代碼以下爲sheet_bottom.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/bottomSheetLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/colorAccent" 
    app:behavior_hideable="true" 
    app:behavior_peekHeight="0dp" 
    android:fitsSystemWindows="true" 
    app:layout_behavior="@string/bottom_sheet_behavior"> 

    <TextView 
     android:id="@+id/bottomsheet_text" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:text="Lorem Ipsum Dolor..." 
     android:textColor="#FFFFFF" /> 
</RelativeLayout> 

Screenshot 在左手側上的圖像的代碼示出了停止Toolbar低於BottomSheet - 這是沒有使用我當前的代碼。目前它看起來像右邊的圖片。

+0

你可以上傳截圖? –

+0

截圖添加到問題 - 編輯 – nor0x

+0

你怎麼樣嘗試把它的高度從底部設置到工具欄,並使底部底片它的孩子,然後將其設置爲匹配它的父母高度(新佈局) –

回答

1

我有同樣的問題。

嘗試讓包括另一CoordinatorLayout裏面你activity_main.xml,具有marginTop這樣的:

<android.support.design.widget.CoordinatorLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:attrs="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.test.MainActivity"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      app:elevation="20dp" 
      android:elevation="20dp" 
      android:layout_height="?attr/actionBarSize"> 

      <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      app:elevation="20dp" 
      android:elevation="20dp" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary"/> 
     </android.support.design.widget.AppBarLayout> 
    </LinearLayout> 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="56dp"> 

     <include layout="@layout/bottom_sheet_additem"/> 

    </android.support.design.widget.CoordinatorLayout> 

</CoordinatorLayout> 

讓我知道它的工作對你來說太。

0

我們可以使用的應用程序:layout_behavior,而不是固定的高度

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <include layout="@layout/bottom_sheet_additem"/> 

</android.support.design.widget.CoordinatorLayout>