每一个人,我都有一个网页视图,我在其上加载了epub书籍的HTML内容。 Web视图内容是分页的,因此用户可以在阅读电子书时水平翻阅页面。 我使用onFlingDo左右滑动,允许用户浏览内容。 我已经自定义了我的webview,如下所示:
public class newBTWebView extends WebView implements QuickAction.OnDismissListener, PopoverView.PopoverViewDelegate, GestureDetector.OnGestureListener {
public newBTWebView(Context context) {
super(context);
this.ctx = context;
setup(context);
init(context);
}
public void init(Context context) {
this.context = context;
this.getSettings().setJavaScriptEnabled(true);
addJavascriptInterface(new MyJavaScriptInterface(this.context), "HTMLOUT");
gestureScanner = new GestureDetector(this);
this.setVerticalScrollBarEnabled(false);
this.setHorizontalScrollBarEnabled(false);
this.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
countDown++;
}
if(event.getAction() == MotionEvent.ACTION_UP && isLongPress)
{
lastTouchedX = (int)event.getX();
lastTouchedY = (int)event.getY();
//get selection
}
return gestureScanner.onTouchEvent(event);
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int[] l = new int[2];
this.getLocationOnScreen(l);
int X = (int)event.getX();
int Y = (int)event.getY();
this.displayR = new Rect(X, Y, X + 100, Y + 20);
return super.onTouchEvent(event);
}
public boolean onFlingDo(float from, float to, float velocityX, float velocityY) {
float diff = Math.abs(to - from);
//swipe left or right depend on diff
}
}
网络视图已连接到此css文件:
html {
height:heightplaceholderpx;
width:100%;
}
body {
margin:0px;
padding:0px;
height:100%;
width:100%;
pointer-events: none;
}
#viewer {
width:widthplaceholderpx;
height:heightplaceholderpx;
}
#book {
width:widthplaceholderpx;
height:heightplaceholderpx;
margin-left:50px;
margin-right:50px;
margin-top:10px;
-webkit-column-count:auto;
-webkit-column-width:widthplaceholderpx;
-webkit-column-gap:100px;
text-align:justify;
}
div.container {
height: 100%;
width:widthplaceholderpx;
overflow-y: hidden;
}
.h {
margin-top:60px;
margin-left:100px;
margin-right:100px;
}
img {
max-width: 100%;
height:auto;
}
我的主要目的是水平和垂直停用拖动,同时保持手势和longClick和超链接工作和而不会水平剪切HTML文件所以用户可以横向浏览书籍。
请注意 overflow-y:hidden; 水平和垂直禁用拖动,但也会剪切内容,因此用户只会看到该章的第一页。
如果有任何含糊不清或需要进一步的细节,请告诉我。 谢谢