【发布时间】:2014-11-20 16:01:24
【问题描述】:
在http://www.google.com/design/spec/patterns/scrolling-techniques.html 中描述了滚动技术。 但是我还没有找到如何实现它的细节。 我正在尝试实现“带图像的灵活空间”有人有这方面的例子吗?
【问题讨论】:
标签: android scroll android-appcompat
在http://www.google.com/design/spec/patterns/scrolling-techniques.html 中描述了滚动技术。 但是我还没有找到如何实现它的细节。 我正在尝试实现“带图像的灵活空间”有人有这方面的例子吗?
【问题讨论】:
标签: android scroll android-appcompat
我认为这个库非常适合您的需要:
https://github.com/ksoichiro/Android-ObservableScrollView
它包括 Google 设计规范中描述的所有滚动技术等等。
此外,它还支持ListViews、GridViews、ScrollViews、RecyclerViews和WebViews。
【讨论】:
我认为this blog post 有你想要的东西。它提供了制作类似布局的指南(尽管您可能需要添加一些代码来为应用栏着色)。
这种“布局技巧”背后的宏伟理念是实现一个带有某种onScrollChanged 侦听器的ScrollView。目的是让您的 Activity 了解滚动更改,然后可以转换所需的元素。
一旦您了解滚动位置(和变化),您就可以使用该值作为基础来应用颜色转换(用于ActionBar 的背景)并重新缩放标题文本。
希望这会有所帮助。
【讨论】:
迟到但并非最不重要,
您需要使用Android Support Design Library v22 或更高版本。特别是 CoordinatorLayout 与 AppBar 布局和工具栏。
<android.support.design.widget.CoordinatorLayout
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">
<! -- Your Scrollable View -->
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
...
app:layout_scrollFlags="scroll|enterAlways">
<android.support.design.widget.TabLayout
...
app:layout_scrollFlags="scroll|enterAlways">
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
【讨论】: