Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 877
chis54 Avatar asked Sep 22 '11 19:09

chis54


1 Answers

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

like image 110
chis54 Avatar answered Oct 22 '22 21:10

chis54