Android WebView下一页/上一页转换
我正在生成一个图书应用程序,可以在Android WebView下一页/上一页转换,android,webview,Android,Webview,我正在生成一个图书应用程序,可以在WebView中显示页面。我有下一个/上一个图像按钮和一个手势叠加来检测左/右滑动。 当我需要更改页面时,我会调用: private void changePage(int delta) { currentPageIndex = currentPageIndex + delta; if (currentPageIndex < 0) { // negative index currentPage
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);
}
}
private void changePage(int delta){
currentPageIndex=currentPageIndex+delta;
如果(currentPageIndex<0){
//负指数
currentPageIndex=0;
}else if(currentPageIndex>=listOfPages.length){
//请求的索引超出列表范围
currentPageIndex=listOfPages.length-1;
}否则{
//设置页面加载的值
文件名=页面列表[currentPageIndex];
mWebView.loadUrl(“file:///android_asset/“+文件名);
}
}
“listOfPages”是我的文件名的字符串数组,loadUrl()工作得很好,但是有没有任何人知道的方法可以通过页面转换来模拟简单的翻页?如果有人感兴趣,我找到了一种方法。 我定义了
动画变量:
Animation slideLeftAnimation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.slide_left);
Animation slideRightAnimation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.slide_right);
而slide\u left
和slide\u right
xml文件来自教程
然后,对于向左或向右滑动,我使用mWebView.startAnimation(leftOrRightAnimation)代码>在mymWebView.loadUrl(url)之前代码>呼叫
希望这对其他人有帮助
克里斯太棒了!我得花上几个小时才能弄明白。