0

AndroidアプリでGoogleマップを表示しています。ユーザーが地図をダブルクリックしたときにズームインしたい。

Map を表示するための 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 のパッケージ名「you put com.is.guide.」が正しい場合。

于 2012-12-07T17:20:48.193 に答える