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

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.