2016-11-17 19 views
1

編輯:我發現我的問題,請參見下面谷歌地圖API的手勢不工作(變焦旋轉...)

我的答案原帖:
我創建一個包含地圖的活動,但我無法添加縮放和其他手勢功能。我可以槍王放大,我可以添加+/-符號來放大通過

googleMap.getUiSettings().setAllGesturesEnabled(true); 

這是我的代碼:

活動的XML(tracking_order.xml)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal"> 

<fragment 
    android:id="@+id/mapFragment" 
    class="com.example.OrderMapFragment" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="3" /> 

<FrameLayout 
    android:id="@+id/clientsFragment" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" /> 

OrderMapFragment.java

public class OrderMapFragment extends SupportMapFragment implements OnMapReadyCallback, GoogleMap.OnMarkerClickListener { 

    public static OrderMapFragment newInstance() { 
     OrderMapFragment fragment = new OrderMapFragment(); 
     Bundle args = new Bundle(); 
     fragment.setArguments(args); 
     return fragment; 
    } 

    @Override 
    public void onAttach(Context context) { 
     super.onAttach(context); 
     ((OrderMapFragment.OnOrderMarkerClickListener) context).setMapObject(this); 
     getMapAsync(this); 
    } 

    @Override 
    public void onMapReady(final GoogleMap googleMap) { 
     googleMap.getUiSettings().setZoomControlsEnabled(true); //this one is working 
     googleMap.getUiSettings().setZoomGesturesEnabled(true); //not working 

     googleMap.getUiSettings().setAllGesturesEnabled(true); //not working 
     // ... (removed code used to fetch markers data) 
    } 

    @Override 
    public boolean onMarkerClick(Marker marker) { 
     return listener.filterListByMarker(marker); 
    } 

    public interface OnOrderMarkerClickListener { 
     /** 
     * Action to be taken when a marker has been clicked 
     * 
     * @param marker 
     * @return true if the listener has consumed the event (i.e., the default behavior should not occur); 
     * false otherwise (i.e., the default behavior should occur). 
     * The default behavior is for the camera to move to the marker and an info window to appear. 
     */ 
     boolean filterListByMarker(Marker marker); //the class that implements this doesn't do anything for now it just returns false 
    } 
} 

謝謝

回答

2

我終於發現了問題啓用。這個類重寫了以下方法:

@Override 
public boolean dispatchTouchEvent(MotionEvent ev) { 
    if (ev.getAction() == MotionEvent.ACTION_UP) { 
     return super.dispatchTouchEvent(ev); 
    } 
    if (ev.getPointerCount() > 1) //here was the problem 
     return true; 
    return super.dispatchTouchEvent(ev); 
} 

所以我創建了一個方法,它改變了這個:

@Override 
public boolean dispatchTouchEvent(MotionEvent ev) { 
    if (ev.getAction() == MotionEvent.ACTION_UP) { 
     return super.dispatchTouchEvent(ev); 
    } 
    if (ev.getPointerCount() > 1 && !enableMultiTouch()) 
     return true; 
    return super.dispatchTouchEvent(ev); 
} 

protected boolean enableMultiTouch(){ 
    return false; //and override it to true in my activity 
} 

希望它可以幫助別人:)

1

評論這條線

googleMap.getUiSettings().setZoomGesturesEnabled(true); //not working 

現在你試試,它會工作。
包含mapFragment被延伸的自定義類的活動:如果您需要任何特定或幾個手勢手段,通過獨立的,否則,如果你需要的一切都只是把這個線

googleMap.getUiSettings().setAllGesturesEnabled(true); 
+0

在fi處我已經嘗試了沒有任何3條線。然後我嘗試了'setZoomControlsEnabled',但它不是我所需要的,然後我單獨嘗試了其他每個人,但都沒有工作。然後我把所有這些問題提出來 – PhpLou

0

在我的情況下,它幫助建立map.getUiSettings().setAllGesturesEnabled(true);並且覆蓋生命週期方法,如MapView documentation中所述:

@Override 
    public void onCreate(Bundle bundle) { 
     super.onCreate(bundle); 
     mapView.onCreate(bundle); 
    } 

    @Override 
    public void onSaveInstanceState() 
    { 
     super.onSaveInstanceState(); 
     mapView.onSaveInstanceState(); 
    } 

    @Override 
    public void onPause() 
    { 
     super.onPause(); 
     mapView.onPause(); 
    } 

    @Override 
    public void onStart() 
    { 
     super.onStart(); 
     mapView.onStart(); 
    } 

    @Override 
    public void onResume() 
    { 
     super.onResume(); 
     mapView.onResume(); 
    } 

    @Override 
    public void onLowMemory() 
    { 
     super.onLowMemory(); 
     mapView.onLowMemory(); 
    } 

    @Override 
    public void onDestroy() 
    { 
     super.onDestroy(); 
     mapView.onDestroy(); 
    } 

    @Override 
    public void onStop() 
    { 
     super.onStop(); 
     mapView.onStop(); 
    }