android - 如何在android支持设计底页中设置最大展开高度?

标签 android android-support-design

我已经展示了我的底部工作表布局,其窥视高度设置为 100dp。但是我怎样才能限制我的底页只扩展到 500dp 呢?这是我的示例布局:

<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>

除了我的问题,如何禁止用户上下拖动底部工作表?

最佳答案

要阻止底部页面向上移动全屏很简单,只需将 NestedScrollView 的 layout_height 设置为 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>

如果您不希望 View 可向上拖动,则需要将 behavior_peekHeightlayout_height 设置为相同的值。

要阻止 View 向下拖动,只需将 behavior_hideable 标志设置为 false

关于android - 如何在android支持设计底页中设置最大展开高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36636671/

相关文章:

android - BottomNavigationView 始终显示图标和文本标签

android - android中的嵌套可扩展 ListView

java - 如果线程只能访问具有自己实例(由不同线程创建)的类的静态方法,那么它将在哪个线程上执行?

android - 在 Android 上处理大位图 - int[] 大于最大堆大小

Android 支持 v23.1.0 更新中断 NavigationView 获取/查找 header

android - 如何从支持设计库向 Nav Drawer 添加计数器

android - 防止 NestedScrollView 自动滚动到顶部

android - 最好使用哪种异常(exception)?或: how to deal with a misconfigured Activity? [closed]

java - 如何在 Android 中创建包含额外内容和过渡的 bundle

android - 如何禁用 BottomNavigationView 移位模式?