Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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         |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
 -----------------------------              ------------------------------

  • User makes a long touch on an item in List 1 and slides from left to right.
  • The view containing List 1 moves from left to right (till the end of the screen) and fades. Screen 2 is shown.

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.

like image 457
500865 Avatar asked Nov 03 '11 15:11

500865


2 Answers

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>
like image 128
Entreco Avatar answered Nov 13 '22 22:11

Entreco


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

like image 21
Paul Nikonowicz Avatar answered Nov 13 '22 20:11

Paul Nikonowicz