chis54 chis54 - 1 month ago 17
Android Question

WebView next/previous page transitions

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

WebView
. I have Next/Previous
ImageButtons
and a
GestureOverlay
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

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!
Chris