在Android中滚动底部工作表的问题

问题描述 投票:0回答:2

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>

main activity.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" />

我需要我的底页停在一定高度。我无法让它像那样工作。请帮忙。提前致谢

android android-layout bottom-sheet
2个回答
0
投票

使用底部的peekHeight属性设置可以滚动最大的最大高度

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

0
投票

像这样使用主布局上方的CollapsingLayout

<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">



        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

然后将您的滚动布局与属性 -

    app:layout_behavior="@string/appbar_scrolling_view_behavior"
© www.soinside.com 2019 - 2024. All rights reserved.