使ViewPager + WebView以连续方式垂直滑动
我正在写一个HTML页面阅读器,无法加载所有.html,因为它的巨大和性能不好,所以我决定将它拆分成3个(或更多)HTML并加载Web视图内嵌视图寻呼机(垂直滑动)
我的问题是我应该慢慢地滑动以滚动web视图并快速滑动以更改视图寻呼机
慢速滑动
快速刷卡在ViewPager上更改页面
1)我可以扩大webview的所有内容高度viewpager内? 2)只有在topScroll或endScroll时才能更改viewpager项目?
到目前为止我尝试过的东西:
CustomWebView
@Override
public boolean onTouchEvent(MotionEvent event) {
requestDisallowInterceptTouchEvent(true);
return super.onTouchEvent(event);
}
工作,但无法改变viewpager项目
所以我虽然关于启用/禁用它,当我到达顶部或结束
删除了webview onTouchEvent并添加:
@Override
protected void onScrollChanged(final int l, final int t, final int oldl, final int oldt) {
requestDisallowInterceptTouchEvent(true);
int height = (int) Math.floor(this.getContentHeight() * this.getScale());
int webViewHeight = this.getMeasuredHeight();
boolean scrollTop = this.getTop() == t;
boolean scrollEnd = this.getScrollY() + webViewHeight >= height;
if(scrollTop || scrollEnd) {
requestDisallowInterceptTouchEvent(false);
}
随机工作,最常见的是,当我改变页面时,我必须向下滚动并向上滚动以触发requestDisallow为false,所以我可以改变页面= [
垂直CustomViewPage是这一个 - >
public class VerticalViewPager extends ViewPager {
public VerticalViewPager(Context context) {
super(context);
init();
}
public VerticalViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
// The majority of the magic happens here
setPageTransformer(true, new VerticalPageTransformer());
// The easiest way to get rid of the overscroll drawing that happens on the left and right
setOverScrollMode(OVER_SCROLL_NEVER);
}
private class VerticalPageTransformer implements ViewPager.PageTransformer {
@Override
public void transformPage(View view, float position) {
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);
} else if (position <= 1) { // [-1,1]
view.setAlpha(1);
// Counteract the default slide transition
view.setTranslationX(view.getWidth() * -position);
//set Y position to swipe in from top
float yPosition = position * view.getHeight();
view.setTranslationY(yPosition);
} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}
}
/**
* Swaps the X and Y coordinates of your touch event.
*/
private MotionEvent swapXY(MotionEvent ev) {
float width = getWidth();
float height = getHeight();
float newX = (ev.getY() / height) * width;
float newY = (ev.getX() / width) * height;
ev.setLocation(newX, newY);
return ev;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev){
boolean intercepted = super.onInterceptTouchEvent(swapXY(ev));
swapXY(ev); // return touch coordinates to original reference frame for any child views
return intercepted;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
return super.onTouchEvent(swapXY(ev));
}
}
相反,您应该在同一WebView中使用“ .js ”/“ jQuery ”和路由页面/ HTML来检测网页的顶部和底部。
window.onscroll = function(ev){if((window.innerHeight + window.scrollY)> = document.body.offsetHeight){//你在页面底部}};
有很多方法可以检测HTML内容的TOP和BOTTOM。
不过,如果您想要将评论的高度增加到内容高度,请使用获取WebView内容高度,一旦其加载Android,它就会为我工作。
链接地址: http://www.djcxy.com/p/41571.html上一篇: Making ViewPager + WebView swipe vertical in continuous way