我正在研究谷歌地图 v2。
我需要在地图触摸上做一些事情,但我无法获得 Google Maps v2 的触摸监听器。
我正在膨胀包含片段 XML 的 XML。
我的代码如下:
public class MapViewHelper {
private FragmentActivity objactivity;
public GoogleMap myMap=null;
public MapViewHelper(FragmentActivity objactivity) {
this.objactivity = objactivity;
}
/*
* @return view of map
*
* @author Sandeep Tiwari
*/
public View getMapView() {
View objView = View.inflate(objactivity, R.layout.homemapview, null);
return objView;
}
public GoogleMap getMap()
{
if (myMap == null) {
// Try to obtain the map from the SupportMapFragment.
myMap = ((SupportMapFragment)this.objactivity.getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
}
return myMap;
}
public class MySupportMapFragment extends SupportMapFragment {
public View mOriginalContentView;
public TouchableWrapper mTouchView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
mOriginalContentView = super.onCreateView(inflater, parent,
savedInstanceState);
mTouchView = new TouchableWrapper(getActivity());
mTouchView.addView(mOriginalContentView);
return mTouchView;
}
@Override
public View getView() {
return mOriginalContentView;
}
}
public class TouchableWrapper extends FrameLayout {
public TouchableWrapper(Context context) {
super(context);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
((MainActivity) objactivity).MotionDown(ev);
break;
case MotionEvent.ACTION_POINTER_DOWN:
((MainActivity) objactivity).MotionPointerDown(ev);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
((MainActivity)objactivity).MotionUp(ev);
break;
case MotionEvent.ACTION_MOVE:
((MainActivity)objactivity).ActionMove(ev);
break;
}
return super.dispatchTouchEvent(ev);
}
}
}
这是我在其中膨胀 xml 的 java 类:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>
</RelativeLayout>
但是当我触摸地图放大缩小地图时,没有任何动作可以指导我。提前致谢。