2
我正在使用Google Maps v2。爲什麼觸摸不適用於谷歌地圖V2?
我需要在地圖觸摸上做一些操作,但我無法獲得Google地圖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);
}
}
}
這是我的Java類中,我膨脹的xml: -
<?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>
但是當我觸摸地圖zoomin縮小地圖不採取行動執行任何一個引導我。 在此先感謝。