首页 > 解决方案 > 在android中滚动底部工作表的问题

问题描述

我在 Android 中的底部工作表的问题是,当我向上滚动工作表时,它会填满整个活动。我需要我的底片在某个高度停下来。

下面是我的代码:

activity_main.xml:-

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="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=".MainActivity">


<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Click here"
    tools:layout_editor_absoluteX="161dp"
    tools:layout_editor_absoluteY="272dp"
    tools:ignore="MissingConstraints" />

<include
    layout="@layout/bottom_sheet"
    android:layout_height="79dp" />
  </android.support.design.widget.CoordinatorLayout>

MainActivity.java

  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    linearLayout = (LinearLayout)findViewById(R.id.linearlayour);
    bottomSheetBehavior = BottomSheetBehavior.from(linearLayout);
    bottomSheetBehavior.setPeekHeight(200);


}

下面是我的 bottom_sheet.xml 文件:-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:id="@+id/linearlayour"

app:behavior_peekHeight="100dp">


<Button
    android:id="@+id/button3"
    android:layout_width="match_parent"
    android:layout_height="16dp"
    android:layout_weight="1"
    android:text="Button" />

<Button
    android:id="@+id/button2"
    android:layout_width="match_parent"
    android:layout_height="16dp"
    android:layout_weight="1"
    android:text="Inside bottom" />

我需要我的底部床单停在某个高度。我无法让它像那样工作。请帮忙。提前致谢

标签: androidandroid-layoutbottom-sheet

解决方案


使用 bottomsheet 的 peekHeight 属性设置它可以滚动的最大高度 max

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:fitsSystemWindows="true"
    app:behavior_hideable="false"
    app:behavior_peekHeight="200dp"
    app:layout_behavior="@string/bottom_sheet_behavior">
    <include layout="@layout/bottom_sheet_content_view" />
</FrameLayout>

推荐阅读