【发布时间】:2019-11-15 21:20:05
【问题描述】:
我想在用户停止滚动时自动完成滚动到顶部/底部。像这样image。 我已经测试过 OnOffsetChangedListener 但总是有问题。 请有什么想法。
没有用于此操作的 java 代码。
这是我的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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"
android:background="?attr/backLayout"
android:animateLayoutChanges="true"
android:fitsSystemWindows="true"
>
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:fitsSystemWindows="true"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<!--app:layout_scrollFlags="scroll|enterAlwaysCollapsed" -->
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
app:contentScrim="?attr/colorPrimary">
...no toolbar
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/collLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7"
>
...content
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScroll"
android:fitsSystemWindows="true"
android:clipToPadding="false"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
...content
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
【问题讨论】:
标签: java android xml android-studio