2016-04-15 43 views
14

我已經顯示了我的底部工作表佈局,其頂部高度設置爲100dp。但是,我怎樣才能限制底部表單擴展到500dp?這是我的樣本佈局:如何在Android支持設計底部表中設置最大展開高度?

<android.support.design.widget.CoordinatorLayout 
android:id="@+id/coordinator" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/map" 
    android:name="com.google.android.gms.maps.SupportMapFragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MapsActivity" /> 

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/design_bottom_sheet" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" 
    app:behavior_hideable="true" 
    app:behavior_peekHeight="100dp" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 

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

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:layout_marginBottom="5dp" 
      android:background="#e444ff" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:layout_marginBottom="5dp" 
      android:background="#e444ff" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:layout_marginBottom="5dp" 
      android:background="#e444ff" /> 

    </LinearLayout> 

</android.support.v4.widget.NestedScrollView> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_margin="@dimen/activity_horizontal_margin" 
    app:layout_anchor="@+id/design_bottom_sheet" 
    app:layout_anchorGravity="top|right|end" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

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

除了我的問題,我怎麼能不允許用戶上下拖動底部表單?

回答

12

停止移動達全屏幕底部片很簡單,只爲您的NestedScrollView到500dp一個layout_height,你也可能需要設置它的layout_gravity="bottom"

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/design_bottom_sheet" 
    android:layout_width="match_parent" 
    android:layout_height="500dp" 
    android:background="#000000" 
    android:layout_gravity="bottom" 
    app:behavior_hideable="true" 
    app:behavior_peekHeight="100dp" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> 

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

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:layout_marginBottom="5dp" 
      android:background="#e444ff" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:layout_marginBottom="5dp" 
      android:background="#e444ff" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:layout_marginBottom="5dp" 
      android:background="#e444ff" /> 

    </LinearLayout> 

</android.support.v4.widget.NestedScrollView> 

,如果你不想要的視圖是可拖動的,那麼你需要將behavior_peekHeightlayout_height設置爲相同的值。

,並從被拖動下停止的觀點是剛剛設置這個behavior_hideable標誌設置爲false

好運和快樂編碼!

+1

很好!這些都是非常聰明的解決方案。非常感謝你! –

+0

你忘了我們應該設置的應用程序:behavior_hideable爲false,所以我們確保底部工作表將不可複製下來 –

+1

這不能解決我的底部工作表高度不幸。 ! – abat

相關問題