我有下一个布局:
<RelativeLayout 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">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/layout_offer_detail_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_offer_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|snap" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/layout_offer_detail_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorBackground"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</>
</>
</>
当用户在列表中向下滚动时,这将隐藏应用栏,并在用户向上滚动时显示它。
我的问题是,在NestedScrollView
的末尾,我有一个“返回顶部”按钮,单击该按钮将触发scrollView向上滚动:scrollView.smoothScrollTo( 0, 0);
问题在于,当用户滚动到顶部时,appBar 不会返回。我无法以编程方式触发应用栏返回。
有什么想法吗?!
编辑
该功能取自此处:see link
最佳答案
这比我想象的要容易。经过三个小时的搜索和尝试,我只需要这样做:
appBarLayout.setExpanded(true, true);
好吧,这对我来说是不必要的时间浪费......
关于android - 触发 AppBar 返回其在 CoordinatorLayout 内的正常位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58587529/