2011-03-23 132 views
0

我有一个自定义的WebView布局如下问题+安卓



class MyWebView extends WebView { 
    private static final int SWIPE_MIN_DISTANCE = 120; 
    private static final int SWIPE_MAX_OFF_PATH = 250; 
    private static final int SWIPE_THRESHOLD_VELOCITY = 200; 
    Context context; 
    GestureDetector gd; 

    public myWebView(Context context) { 
    super(context); 

    this.context = context; 
     gd = new GestureDetector(context, sogl); 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent event) { 
    return gd.onTouchEvent(event); 
    } 

    GestureDetector.SimpleOnGestureListener sogl = new GestureDetector.SimpleOnGestureListener() { 
     public boolean onDown(MotionEvent event) { 
     return true; 
     } 

     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 
      try { 
      if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) 
       return false; 
      // right to left swipe 
      if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 

      //  mScrollwidth=mScrollwidth+mWebView.getWidth(); 
      // mWebView.scrollTo(mScrollwidth,0); 
       //System.out.println(mScrollwidth); 

      } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 

      // mScrollwidth=mWebView.getWidth(); 
       // mWebView.scrollTo((mScrollwidth-mWebView.getWidth()),0); 
      } 
     } catch (Exception e) { 
      // nothing 
     } 
     return false; 
     } 
    }; 


    } 

和我如下与图像视图进行合并,

<merge 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:MyWebView="http://schemas.android.com/apk/res/com.mireader.mywebview"> 
<ImageView 
    android:layout_width="120px" 
    android:layout_height="110px" 
    android:scaleType="center" 
    android:src="@drawable/d" /> 

<com.mireader.mywebview.MyWebView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

</merge> 

我收到提示在运行时如下,
java.lang.RuntimeException:无法启动活动ComponentInfo {com.mireader/com.mireader.demoweb}:android.view.InflateException:二进制XML文件行#11:错误的类com.mireader.mywebview .MyWebView

回答

1

构造函数改成这样

public myWebView(Context context, AttributeSet attr) { 
super(context, attr); 

this.context = context; 
    gd = new GestureDetector(context, sogl); 
} 
+0

@ Tox1c谢谢...ü让我很快乐:) – vnshetty 2011-03-23 11:19:03