Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PageCurl animations on ViewPager transitions?

Here's a demo of what a page curl animation looks like: http://www.youtube.com/watch?v=aVZHN_o45sg

There are a couple of page curl animation libraries:

  • https://github.com/harism/android_page_curl
  • https://github.com/MysticTreeGames/android-page-curl

They are meant to work with Bitmap Drawables and not necessarily ViewGroups. If was wondering if anyone has come up with a similar page curl transition for ViewPagers.

like image 516
Anup Cowkur Avatar asked Apr 05 '13 08:04

Anup Cowkur


People also ask

What is the use of viewpager in Android?

It enables users to switch smoothly between fragments which have a common UI and it’s the best way to make your app extraordinary from others. ViewPagers provide visual continuity. They basically keep track of which page is visible and then ask PageAdapter to display the next page in the hierarchy.

Can you see the edges of adjacent views in a viewpager?

Before we dive into code, let’s show off the finished effect (the source and sample apk can be found at the bottom of the article): As you can see, the background of the ViewPager animates gradually, so you can’t see the edges of adjacent views.

How do I use the valueanimator to change the color of a page?

Normally when using ValueAnimator you would set the duration and start the animation by calling ValueAnimator#start (), but we’re only going to use the animator for determining the right color in each state of swiping between pages. To calculate the color we need to know what is the ViewPager currently showing.


2 Answers

Not a straight way..but, How about creating the bitmap of view group by getDrawingCache() method and pass the bitmap to library.

like image 132
sha Avatar answered Oct 04 '22 02:10

sha


This is a library that I just come across; it has a nice page curl transformation. It is not the exact same page curl that you want; but maybe some remedy to anyone

How it looks

Dependency

implementation 'com.wajahatkarim3.easyflipviewpager:easyflipviewpager:1.0.0'

Usage

// Get ViewPager and Set Adapter        
myViewPager = findViewById(R.id.myViewPager);
pagerAdapter = new MyPagerAdapter(this);
myViewPager.setAdapter(pagerAdapter);

// Create an object of page transformer
BookFlipPageTransformer bookFlipPageTransformer = new BookFlipPageTransformer();

// Enable / Disable scaling while flipping. If true, then next page will scale in (zoom in). By default, its true.
bookFlipPageTransformer.setEnableScale(true);

// The amount of scale the page will zoom. By default, its 5 percent.
bookFlipPageTransformer.setScaleAmountPercent(10f);

// Assign the page transformer to the ViewPager.
myViewPager.setPageTransformer(true, bookFlipPageTransformer);
like image 30
Zain Avatar answered Oct 04 '22 00:10

Zain