TomS
TomS

Reputation: 511

Alternative to ViewPager in Android

I would like to build some Activity which consists of several screens (Fragments) with one GridView in each. This Activity uses ViewPager from the Support library. This is working pretty well.

When clicking one item in one of the GridViews, the page should automatically turn (flip) and show more details on that item.

Both the ViewPager and the Flip transitions are working pretty well with one cosmetic issue: When flipping the GridView Fragment to the details view Fragment, the GridView is not animated. The flipping in details Fragment is perfectly animated and is flying in, but the GridView which should do a fly-out transition is not animated at all.

I'm not an expert on Android programming, but I guess that the root cause of this behaviour is that the ViewPager is part of the Support library and thus does not support this custom animation transaction.

Could I be right? Is there an easy-to-use alternative to ViewPager which also supports custom animations?

Upvotes: 2

Views: 9102

Answers (2)

SteelBytes
SteelBytes

Reputation: 6965

Not sure if this is an answer, but ViewPager does support custom animations. See http://developer.android.com/training/animation/screen-slide.html#pagetransformer

Upvotes: 3

R4ng3LII
R4ng3LII

Reputation: 457

If you changing Fragments in your app, than you should use FragemntTransaction instead of ViewPager. With this you can customize the animation of the new and the old Fragment.

For example:

FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
      .setCustomAnimations(R.anim.slide_in_from_bottom, 
                           R.anim.slide_out_to_top,
                           R.anim.slide_in_from_top, 
                           R.anim.slide_out_to_bottom)
      .replace(R.id.MainLayout, newFragment, NewFragment.TAG).commit();

But here is an article about the : flip animation

You can use the NineOldAndroids lib, which backports the ObjectAnimator and ValueAnimator

Upvotes: 2

Related Questions