我在我的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
答案 0 :(得分: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上的包装名称“你放了com.is.guide。”是正确的。