我们试图处理Cross Walk XWalkView版本12.41.296.9-x86的滚动事件,但未调用滚动。

    public class CustomXWalkView extends XWalkView{

    public CustomXWalkView(Context arg0, Activity arg1) {
        super(arg0, arg1);
    }

    public CustomXWalkView (Context context, AttributeSet attrs)  {
        super(context, attrs);
    }



    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        Log.d("I'm scrolling", "do");
    }
}


如何获取onScrollChanged事件是XWalkView。

最佳答案

下面的自定义Web视图解决了我的问题。希望能帮助到你

package com.example.crosswalkexample;

import org.chromium.content.browser.ContentViewCore;
import org.xwalk.core.XWalkView;
import org.xwalk.core.internal.XWalkViewBridge;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;

public class CustomCrossWalkView extends XWalkView implements ContentViewCore.InternalAccessDelegate {


    private XWalkViewBridge mWalkViewBridge;
    private ContentViewCore mContentViewCore;

    public CustomCrossWalkView(Context context, Activity arg1) {
        super(context, arg1);
        init();
    }

    public CustomCrossWalkView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init(){
        if(this.getChildCount() > 0){
            mWalkViewBridge = (XWalkViewBridge) this.getChildAt(0);
        }else{
            throw new Error("XWalkWebView Bridge not found");
        }
        mContentViewCore = mWalkViewBridge.getXWalkContentForTest();
        mContentViewCore.setContainerViewInternals(this);
    }

    @Override
    public boolean super_awakenScrollBars(int arg0, boolean arg1) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean super_dispatchKeyEvent(KeyEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean super_dispatchKeyEventPreIme(KeyEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void super_onConfigurationChanged(Configuration arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean super_onGenericMotionEvent(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean super_onKeyUp(int arg0, KeyEvent arg1) {
        // TODO Auto-generated method stub
        return false;
    }


    @Override
    public boolean awakenScrollBars() {
        // TODO Auto-generated method stub
        return super.awakenScrollBars();
    }

    @Override
    public boolean drawChild(Canvas canvas, View child, long drawingTime) {
        // TODO Auto-generated method stub
        return super.drawChild(canvas, child, drawingTime);
    }

    @Override
    public void onScrollChanged(int l, int t, int oldl, int oldt) {
        // TODO Auto-generated method stub
        Log.d("onScrollChanged", "Scorlling");
        super.onScrollChanged(l, t, oldl, oldt);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        // TODO Auto-generated method stub
        return super.dispatchTouchEvent(ev);
    }


}

10-08 12:32