500865
500865

Reputation: 7120

Is it possible to do this Android screen animation with a ViewPager?

I need to make 2 screens with custom animation like explained below :


          Screen 1                                    Screen 2
 -----------------------------              ------------------------------
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|       List 1      |  List2  | ---------> | List 3 |      List 4         |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
 -----------------------------              ------------------------------

Is it possible to do this animation using ViewPager? If yes, How?

I would like to do this via ViewPager because I'm using Fragments pretty extensively and I have implemented many screens as fragments already.

If anyone needs clarification about the animation or the UI, please let me know.

Update : I was able to implement both of the screens in a single activity which I have partially explained here. I can implement the same in a single fragment. But being able to implement as different Fragments in a ViewPager would still help.

Upvotes: 13

Views: 2371

Answers (2)

Paul Nikonowicz
Paul Nikonowicz

Reputation: 3903

I have successfully used vertical ListViews inside of ViewPagers before. How about trying a horizontal scrolling list view inside of your ViewPager?

Upvotes: 2

Entreco
Entreco

Reputation: 12900

ViewPager, too me, seems like overkill. Unless you want to add more screens later, or some other requirement. For these simple screens you can do it with ActivityAnimations. If you put Screen1 and Screen2 in a seperate Activity, you can animate the Activities using simple styles. You don't need to code, simply define the Enter and Exit styles for your activities, and they will be executed.

So, unless you have another reason for using the ViewPager, you can accomplish the same effect by the following (not tested):

Android Manifest.xml

<activity android:name=".Screen1" android:theme="@style/Animated"></activity>
<activity android:name=".Screen2"></activity>

Your themes.xml

<resources>
    <style name="Animated">
        <item name="android:windowAnimationStyle">@style/Animation.ScreenAnimation</item>
    </style>
</resources>

Finally, in your styles.xml

<style name="Animation"></style>
<style name="Animation.ScreenAnimation" parent="android:style/Animation.Activity">
    <item name="android:activityOpenEnterAnimation">@anim/slide_in_right</item>
    <item name="android:activityOpenExitAnimation">@anim/slide_out_left</item>
    <item name="android:activityCloseEnterAnimation">@anim/slide_out_left</item>
    <item name="android:activityCloseExitAnimation">@anim/slide_in_right</item>
</style>

Upvotes: 3

Related Questions