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

остановить нижний лист от перемещения вверх весь экран просто, просто установить layout_height для NestedScrollView к 500dp, и вы, вероятно, хотите, чтобы установить это 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_peekHeight и layout_height на те же значения.

И остановить взгляд от того, перетаскивать вниз является behavior_hideable флаг просто установить это ложное

Удачи и счастливого кодирования!

+1

это хорошо! это довольно умные решения. Большое спасибо! –

+0

ow вы забыли что-то, что мы должны установить app: behavior_hideable в false, поэтому мы гарантируем, что нижний лист будет недоступен. –

+1

Это, к сожалению, не зафиксировало мою нижнюю высоту листа. ! – abat