【发布时间】:2015-12-21 14:57:38
【问题描述】:
我正在尝试在搜索登录页面中使用类似于 Google 地图应用的折叠工具栏。也就是说,存在三个“锚点”或位置。我会用图片代替地图。
- 工具栏已折叠(内容为全屏)
- 中间位置
- 工具栏已扩展,仅显示一些内容(永久底部表格)
应用程序最好在这些位置之间对齐。
到目前为止,我的布局基本正常。
两个主要问题是:
- 在 NestedScrollView 内翻页无法正常工作。即使它正在使用
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior",它也会停止/停止。我相信这是AppBarLayout的错误 - 上述锚点未实现。
这是我的布局:
请注意,app:layout_behavior="@string/appbar_anchor_behavior"> 只是 AppBarLayout.Behavior 的未修改子类
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/actions_bar_dark"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_anchor_behavior">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/item_preview_thumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:layout_centerInParent="true"
app:layout_collapseMode="parallax"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/contentRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include layout="@layout/item_detail_content"/>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:src="@drawable/ic_download"
android:layout_margin="16dp"
android:clickable="true"/>
如何使用自定义行为来实现这一点?
【问题讨论】:
-
也许他们没有使用折叠工具栏来制作上面的东西。
-
他们正在使用未折叠工具栏的slidingBottomPanel。
-
@k0sh 你能说得更具体点吗?
-
我看到人们使用 umanos' AndroidSlidingUpPanel 来处理这种行为。