Skip to main content

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 Fragment s 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 Fragment s in a ViewPager would still help.



Source: Tips4all

Comments

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

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

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex