خرید بک لینک

Vote count: 0

I have a SupportMapFragment and I am trying to draw a user drawn line, exactly like here, I am trying to use this questions accepted answer using Alteative Method #2, which seems to allow you to put the SupportMapFragment in a FrameLayout. However, I can't get it to work for me. It seems like the View of the MapFragment has requestDisallowInterceptTouchEvent() set to true, preventing me from consuming the touch events properly, but I can consume the touch events on the parts of the screen not containing the map fragment. All of the questions I've seen on here seem to do the opposite of what I want to do.

Here's my xml code relevant to the map (root linearlayout contains other viewgroups, not relevant to this):

<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 setup in MainActivity.onCreate():

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

mapFragment.getMapAsync(this);

Where I'm trying to consume touch events:

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;
            }
            retu true;
        }});

All I get in my logcat when I touch in the map area (I disabled the .setScrollGesturesEnabled()) :

D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: جمعه 13 فروردين 1395 ساعت: 23:52

صفحه بندی