Android 安卓5.0-实现谷歌播放电影素材设计“;“我的电影”;屏幕
我想从新的GPlay Movies材质版本中实现该屏幕: 如果你还没有试过这个应用程序,最好的办法就是查看一下 因此,我有一个Android 安卓5.0-实现谷歌播放电影素材设计“;“我的电影”;屏幕,android,header,parallax,android-5.0-lollipop,android-recyclerview,Android,Header,Parallax,Android 5.0 Lollipop,Android Recyclerview,我想从新的GPlay Movies材质版本中实现该屏幕: 如果你还没有试过这个应用程序,最好的办法就是查看一下 因此,我有一个RecyclerView和一个GridLayoutManager用于网格。我考虑在网格中添加一个红色背景的标题视图。注意,我还想在这个标题视图中添加与电影应用程序相同的视差效果 目前,我并不真正需要标签的支持(我想让它与RecyclerView一起工作,而不是ViewPager) 我曾经用一种基于Cyrill Mottier的这首短裙和Flavien Laurent的源
RecyclerView
和一个GridLayoutManager
用于网格。我考虑在网格中添加一个红色背景的标题视图。注意,我还想在这个标题视图中添加与电影应用程序相同的视差效果
目前,我并不真正需要标签的支持(我想让它与RecyclerView
一起工作,而不是ViewPager
)
我曾经用一种基于Cyrill Mottier的这首短裙和Flavien Laurent的源代码的解决方案来制作这种屏幕。但这些解决方案适用于列表视图
或滚动视图
,但(尚未)适应回收视图
你对如何使这项工作起作用有什么想法吗
提前感谢,
VieuMa在“我的电影”屏幕(或Google Play Music应用程序)中滚动时,会发生很多事情。以下是基本工作原理: 总体思路
RecylcerView
工具栏
容器视图OnScrollListener
添加到RecyclerView
(更难的部分)。使用dy
(y方向的增量)来
视差滚动彩色视图。如果向下滚动,请进行翻译
工具栏容器朝向屏幕顶部。如果嘲笑
向上显示工具栏容器(除非它已可见)<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Actual content (could also be in a fragment -->
<View
android:id="@+id/coloredView"
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="#CC0000" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="12dp"
android:layout_marginLeft="12dp"
android:paddingTop="120dp"
android:clipToPadding="false" />
<!-- Toolbar (container) -->
<LinearLayout
android:id="@+id/toolbar_container"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:layout_gravity="top"
android:gravity="center_vertical"
android:background="#CC0000"
android:minHeight="0dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
style="@style/Toolbar" />
<!-- Fake tab ;) -->
<TextView
android:layout_width="match_parent"
android:layout_height="48dp"
android:text="Dummy tab"
android:background="#CC0000"
android:padding="16dp"
android:textAllCaps="true"
android:textColor="#fff" />
</LinearLayout>
</FrameLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Init your recyclerview here.
final View toolbarContainer = findViewById(R.id.toolbar_container);
final View coloredView = findViewById(R.id.coloredView);
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy < 0) {
onScrollUp(dy);
} else {
onScrollDown(dy);
}
}
private void onScrollDown(int dy) {
coloredView.setTranslationY(coloredView.getTranslationY() - dy / 3);
toolbarContainer.setTranslationY(toolbarContainer.getTranslationY() - dy);
}
private void onScrollUp(int dy) {
coloredView.setTranslationY(coloredView.getTranslationY() - dy / 3);
if (toolbarContainer.getTranslationY() < 0) {
showToolbar();
}
}
private void showToolbar() {
toolbarContainer.animate()
.translationY(0)
.setDuration(200)
.setInterpolator(new DecelerateInterpolator())
.start();
}
});
在MainActivity.java的onCreate()中:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Actual content (could also be in a fragment -->
<View
android:id="@+id/coloredView"
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="#CC0000" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="12dp"
android:layout_marginLeft="12dp"
android:paddingTop="120dp"
android:clipToPadding="false" />
<!-- Toolbar (container) -->
<LinearLayout
android:id="@+id/toolbar_container"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:layout_gravity="top"
android:gravity="center_vertical"
android:background="#CC0000"
android:minHeight="0dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
style="@style/Toolbar" />
<!-- Fake tab ;) -->
<TextView
android:layout_width="match_parent"
android:layout_height="48dp"
android:text="Dummy tab"
android:background="#CC0000"
android:padding="16dp"
android:textAllCaps="true"
android:textColor="#fff" />
</LinearLayout>
</FrameLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Init your recyclerview here.
final View toolbarContainer = findViewById(R.id.toolbar_container);
final View coloredView = findViewById(R.id.coloredView);
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy < 0) {
onScrollUp(dy);
} else {
onScrollDown(dy);
}
}
private void onScrollDown(int dy) {
coloredView.setTranslationY(coloredView.getTranslationY() - dy / 3);
toolbarContainer.setTranslationY(toolbarContainer.getTranslationY() - dy);
}
private void onScrollUp(int dy) {
coloredView.setTranslationY(coloredView.getTranslationY() - dy / 3);
if (toolbarContainer.getTranslationY() < 0) {
showToolbar();
}
}
private void showToolbar() {
toolbarContainer.animate()
.translationY(0)
.setDuration(200)
.setInterpolator(new DecelerateInterpolator())
.start();
}
});
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//在这里初始化你的回收视图。
最终视图toolbarContainer=findViewById(R.id.toolbar\u容器);
最终视图coloredView=findViewById(R.id.coloredView);
recyclerView.setOnScrollListener(新的recyclerView.OnScrollListener(){
@凌驾
已填空的公共空间(RecyclerView RecyclerView、int dx、int dy){
super.onScrolled(recyclerView、dx、dy);
if(dy<0){
onScrollUp(dy);
}否则{
onScrollDown(dy);
}
}
私有void onScrollDown(int-dy){
coloredView.setTranslationY(coloredView.getTranslationY()-dy/3);
toolbarContainer.setTranslationY(toolbarContainer.getTranslationY()-dy);
}
私有void onScrollUp(int-dy){
coloredView.setTranslationY(coloredView.getTranslationY()-dy/3);
if(toolbarContainer.getTranslationY()<0){
showToolbar();
}
}
私有void showToolbar(){
toolbarContainer.animate()
.translationY(0)
.setDuration(200)
.setInterpolator(新减速器Interpolator())
.start();
}
});
结果
(我省略了一些小细节,比如工具栏阴影,或者如果工具栏未完全隐藏,则显示其完整高度的工具栏。)
希望有帮助
PS:你的问题的标题非常具体。也许你应该把它改成“像在谷歌播放/播放音乐中一样在循环视图滚动条上隐藏工具栏”,这样这个线程更容易找到;)