0

我在我的 android 应用程序中显示谷歌地图。当用户双击地图时,我想放大。

我有 xml 来显示地图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<com.is.guide.ExtMapView
    android:id="@+id/tourMapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
     android:clickable="true"
    android:apiKey="@string/apikey" />

和类如下

public class ExtMapView extends MapView {
 private Context context;
 private GestureDetector gestureDetector;

 @SuppressWarnings("deprecation")
public ExtMapView(Context c, AttributeSet attrs) {
  super(c, attrs);
  context = c;

  gestureDetector = new GestureDetector((OnGestureListener) context);
  gestureDetector.setOnDoubleTapListener((OnDoubleTapListener) context);
 }

 public boolean onTouchEvent(MotionEvent ev) {
  if (this.gestureDetector.onTouchEvent(ev))
   return true;
  else
   return super.onTouchEvent(ev);
 }
}

运行应用程序时出现 view.InflateException :(

我可能错过了什么?

异常如下

12-07 21:26:09.788: E/AndroidRuntime(6714): java.lang.RuntimeException: 
Unable to start activity ComponentInfo{com.is.guide/com.is.TourMapActivity}:
android.view.InflateException: Binary XML file line #7: Error inflating class 
com.is.guide.ExtMapView

12-07 21:26:09.788: E/AndroidRuntime(6714): Caused by: android.view.InflateException: 
Binary XML file line #7: Error inflating class com.is.guide.ExtMapView

我提到了这个链接 http://dev.kafol.net/2011/11/how-hard-is-it-to-make-simple-zoom-in.html

4

1 回答 1

0

覆盖所有构造函数

public ExtMapView(Context arg0, String arg1) {
    super(arg0, arg1);
    init(arg0);
}

public ExtMapView(Context arg0, AttributeSet arg1) {
    super(arg0, arg1);
    init(arg0);
}

public ExtMapView(Context arg0, AttributeSet arg1, int arg2) {
    super(arg0, arg1, arg2);
    init(arg0);
}

protected void init(Context c) {
    context = c;
    gestureDetector = new GestureDetector((OnGestureListener) context);
    gestureDetector.setOnDoubleTapListener((OnDoubleTapListener) context);
}

如果您有以下标签,请在您的 manifest.xml 中进行验证

<uses-library android:name="com.google.android.maps"/> 

如果 xml 上的 packge 名称“你放 com.is.guide. ”是正确的。

于 2012-12-07T17:20:48.193 回答