WebView下一个/上一个页面转换

WebView下一个/上一个页面转换

问题描述:

我正在生成一个书籍应用程序,用于显示WebView中的页面。我有Next/Previous ImageButtonsGestureOverlay来检测左/右滑动。 当我想换页我打电话:WebView下一个/上一个页面转换

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”是我个人的文件名和使用loadURL()的伟大工程的一个字符串数组,但没有任何方式,任何人知道的是能够有一个页面过渡到模拟简单的页面转向?

如果有人有兴趣,我找到了一种方法来做到这一点。 我定义Animation变量:

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

而且slide_leftslide_right XML文件是从Android API教程。

然后,对于向左或向右滑动,我在调用mWebView.loadUrl(url);之前使用了mWebView.startAnimation(leftOrRightAnimation);

希望这可以帮助其他人!
Chris

+1

太棒了!这需要花几个小时才能弄清楚。 – sven