2016-04-15 44 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

相关问题