1

私はSupportMapFragmentを持っていて、hereとまったく同じように、ユーザーが描いた線を描こうとしています。代替メソッド#2を使用してこの質問を受け入れようとしています。 FrameLayoutのSupportMapFragmentです。しかし、私はそれを私のために働かせることはできません。 MapFragmentのViewでrequestDisallowInterceptTouchEvent()がtrueに設定されているため、タッチイベントを適切に消費できなくなっているようですが、マップフラグメントが含まれていない部分のタッチイベントを消費する可能性があります。私がここで見たすべての質問は、私がやりたいことの反対をするようです。 MainActivity.onCreate()内GoogleMapフラグメントブロックカスタムタッチイベント

<LinearLayout> 
    <FrameLayout 
     android:id="@+id/fram_map" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:id="@+id/mapFrag" tools:context=".MapsActivity" 
     android:name="com.google.android.gms.maps.SupportMapFragment" /> 


    </FrameLayout> 

</LinearLayout> 

MapFragmentセットアップ:

は、ここで(ルートのLinearLayoutはこれに関連していない他のviewgroups、含まれている)マップに私のXMLコードが関連性の

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.mapFrag); 

mapFragment.getMapAsync(this); 

Iタッチイベントを消費しようとしています:

FrameLayout fram_map = (FrameLayout) findViewById(R.id.fram_map); 

     fram_map.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View v, @NonNull MotionEvent event){ 

      float startX; 
      float startY; 
      float endX; 
      float endY; 
      switch (event.getAction()){ 
       case MotionEvent.ACTION_DOWN: 
        startX = event.getX(); 
        startY = event.getY(); 
        LatLng pt = mMap.getProjection().fromScreenLocation(new Point((int) startX,(int) startY)); 
        System.out.println("Start: " + pt.toString()); 
        break; 
       case MotionEvent.ACTION_MOVE: 
        //check for difference in prev once 
        endX = event.getX(); 
        endY = event.getY(); 
        System.out.println("Moving: " + endX); 
        break; 
       case MotionEvent.ACTION_UP: 
        endX = event.getX(); 
        endY = event.getY(); 
        System.out.println("Stop: " + endX); 
        break; 
      } 
      return true; 
     }}); 

私はタッチイベントを消費しようとしています地図領域(Iは.setScrollGesturesEnabled(無効)):

D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN 

答えて

1

問題は地図の断片が、FrameLayoutの内側にあるということです。あなたのレイアウトを変更する必要があります。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <fragment 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/mapFrag" 
     tools:context=".MapsActivity" 
     android:name="com.google.android.gms.maps.SupportMapFragment" /> 

    <FrameLayout 
     android:id="@+id/fram_map" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 

</FrameLayout> 

また、推奨として、代わりにLogを使用し、System.out.println()を使用しないでください。例:Log.e("MOTION", "Start: " + pt.toString());

+0

この回答があなたの質問を解決しましたか? – antonio

+0

はい、あなたは解決策ですが、地図を拡大する機能を無効にします。マップを描画する必要があるときはいつでもレイアウトをプログラムで変更する必要がありますか? –

+0

はい、 'View.OnTouchListener'でfalseを返すビューの動作をプログラムで変更するか、' map.dispatchTouchEvent(motionEvent);を使用して 'MotionEvent'をマップにディスパッチする必要があります – antonio

関連する問題