![](/img/trans.png)
[英]Android - Create music player for android like Play Music from Google?
[英]ViewPager transition like Google Play Music “Player”
我希望模仿您在Play音乐应用的播放器界面中看到的ViewPager过渡动画。 看起来像这样。
现在,可以使用此处描述的自定义PageTransformer轻松完成放大/淡入动画,难度部分只是带有歌曲信息和内容的顶部栏。 这个只是像普通的ViewPager那样滑入。
对我来说,因此看起来谷歌以某种方式将两个PageTransformers组合在一起布局的不同部分(1.顶部栏,2。封面艺术)。 我不知道怎么做,如果有可能的话。 我可以想象开发人员做的另一种方式是拥有两个ViewPagers。 一个用于歌曲信息栏,另一个用于隐蔽艺术,然后将共享触摸事件以同时滑动/动画。 然而,对我来说,这听起来有点不方便,并且喜欢使用大量CPU的东西。
有什么建议?
PageTransformer
不必影响整个View
,毕竟定义会发生什么的是你。 考虑到ViewPager
中的Fragments
布局如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/top_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</RelativeLayout>
<RelativeLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</RelativeLayout>
</LinearLayout>
正如您所看到的,有两个不同的RelativeLayouts
它们都有一个id。 这样,您只需调用findViewById()
在View
里面PageTransformer
和不同变换布局的不同部分!
public class ExampleTransformer implements ViewPager.PageTransformer {
public void transformPage(View view, float position) {
View topBar = view.findViewById(R.id.top_bar);
View content = view.findViewById(R.id.content);
if (position < -1) {
content.setAlpha(0);
} else if (position <= 1) {
// Now you can fade the content without affecting the topBar
content.setAlpha(...);
// And by setting the translation on the root view you
// can move everything at the same time
view.setTranslationX(...);
} else {
content.setAlpha(0);
}
}
}
我希望我可以帮助你,如果你有任何进一步的问题,请随时提出!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.