WebView下一个/上一个页面过渡 [英] WebView next/previous page transitions
问题描述
我正在生成一种图书应用程序,可以在 WebView
中显示页面.我有下一个/上一个 ImageButtons
和一个 GestureOverlay
来检测向左/向右滑动.当我想换页时,我打电话:
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'是我的文件名的字符串数组,并且loadUrl()很好用,但是任何人都知道有什么方法能够进行页面转换以模拟简单的页面转向吗?
'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?
推荐答案
如果有人感兴趣,我找到了一种方法.我定义了 Animation
变量:
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);
slide_left
和 slide_right
xml文件来自
And the slide_left
and slide_right
xml files are from the Android API tutorials.
然后,对于左右滑动,我在 mWebView.loadUrl(url);
调用之前使用了 mWebView.startAnimation(leftOrRightAnimation);
.
希望这对其他人有帮助!
克里斯
Then, for left or right swipes, I used mWebView.startAnimation(leftOrRightAnimation);
before my mWebView.loadUrl(url);
call.
Hope this helps anyone else!
Chris
这篇关于WebView下一个/上一个页面过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!