开发者

WebView next/previous page transitions

开发者 https://www.devze.com 2023-04-06 15:35 出处:网络
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.

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 开发者_StackOverflow社区= 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号