android 中底部 sheet 的滚动问题
Problem in scrolling of bottom sheet in android
我在 Android 中底部 sheet 的问题是,当我向上滚动 sheet 时,它会填满整个 activity。
我需要我的屁股 sheet 在一定高度停下来。
下面是我的代码:
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" />
我需要我的屁股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>
像这样在主布局上方使用 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"
我在 Android 中底部 sheet 的问题是,当我向上滚动 sheet 时,它会填满整个 activity。 我需要我的屁股 sheet 在一定高度停下来。
下面是我的代码:
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" />
我需要我的屁股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>
像这样在主布局上方使用 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"