chis54 chis54 - 1 year ago 134
Android Question

WebView next/previous page transitions

I'm generating a book app, of sorts, that displays pages in a

. I have Next/Previous
and a
to detect left/right swipes.
When I want a page change I call:

private void changePage(int delta) {
currentPageIndex = currentPageIndex + delta;
if (currentPageIndex < 0) {
// negative index
currentPageIndex = 0;
} else if (currentPageIndex >= listOfPages.length) {
// index requested is out of range of the list
currentPageIndex = listOfPages.length - 1;
} else {
// set values for page load
filename = listOfPages[currentPageIndex];
mWebView.loadUrl("file:///android_asset/" + filename);

'listOfPages' is a string array of my filenames and loadUrl() works great, but is there any way that anyone knows of to be able to have a page transition to simulate a simple page turn?

Answer Source

If anyone's interested, I found a way to do this. I defined Animation variables:

Animation slideLeftAnimation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.slide_left);
Animation slideRightAnimation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.slide_right);

And the slide_left and slide_right xml files are from the Android API tutorials.

Then, for left or right swipes, I used mWebView.startAnimation(leftOrRightAnimation); before my mWebView.loadUrl(url); call.

Hope this helps anyone else!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download