如何在ViewPager位置偏移更改时为视图设置动画 [英] How to animate views as the ViewPager position offset changes

查看:203
本文介绍了如何在ViewPager位置偏移更改时为视图设置动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想创建一个带有动画的应用介绍,其中用户滚动页面,并且随着用户滚动,视图被动画化并遍历所有幻灯片。动画视图应随用户滚动而移动,因此,如果用户滚动得更快,动画视图应移动得更快,并且如果用户向后滚动到上一页,则动画视图应向后移动。

We would like to create an app intro with animation where the user scrolls through pages and, as the user scrolls, a view is animated and travels through all the slides. The animated view should move as the user scrolls, so if the user scrolls faster the animated view should move faster and if the user scrolls back to a previous page, the animated view should move backwards.

在iOS中使用 https://github.com/IFTTT/JazzHands 超级简单,但是我做不到找到在Android中执行此操作的方法。

This is super easy in iOS with https://github.com/IFTTT/JazzHands but I can't find a way to do this in Android.

我发现的问题:


  • 动画实时运行;您不能让时间成为ViewPager的偏移量。

  • FragmentPagerAdapter 中,无法将一个片段的视图移动到另一个片段。

  • Animations run in real time; you can't let the time be the ViewPager offset.
  • In FragmentPagerAdapter, views from one fragment can't be moved to another fragment.

有什么建议吗?谢谢。

推荐答案

第二个问题:

viewPagerAdapter会在不再需要视图时破坏视图,以便使视图在所有需要的页面中可见,并将其添加到包含ViewPager的布局中。

The viewPagerAdapter will destroy the views when they are no more needed so to keep a view visible through all the pages you need add it to the layout that contains the ViewPager.

类似这样的东西可以工作:

Something like this can works:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white_transparent"
        />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text out of view pager"
        android:textSize="25sp"
        />
</RelativeLayout>

这篇关于如何在ViewPager位置偏移更改时为视图设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆