合并Layouts + android中的问题

时间:2011-03-23 10:20:49

标签: android merge webview

我有一个自定义的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 个答案:

答案 0 :(得分:1)

将构造函数更改为此

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

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