Google map V2 and navigation drawer

心已入冬 提交于 2019-12-10 12:16:17

问题


PROBLEM

I want to use Google Map V2 in Navigate Drawer but I can't disable Navigate Drawer

and give touch handler to the map when it was touched. What should I do ???

NOTE

I have experience the similar problem like this before...

I would like to use SeekBar in Navigate Drawer and it can't scroll the SeekBar.

At that time, I can archive it by using onTouchListener() for SeekBar directly but now it cannot.


回答1:


SOLUTION

So, here is my solution thank to this post, I have adapt some code to archive my goal.

STEP 1 :: create TouchableWrapper Class for MySupportMapFragment

STEP 2 :: override dispatchTouchEvent() and do as the following

public  class TouchableWrapper extends FrameLayout {

    public TouchableWrapper(Context context) {
        super(context);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {

        ViewParent v;
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                v = this.getParent();
                v.requestDisallowInterceptTouchEvent(true);
                break;
            case MotionEvent.ACTION_UP:
                v = this.getParent();
                v.requestDisallowInterceptTouchEvent(false);
                break;
        }
        return super.dispatchTouchEvent(ev);
    }
}

STEP 3 :: Create MySupportMapFragment Class and bind it with TouchableWrapper

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;
    }

}

STEP 4 :: Change your original xml Map Fragment to your custom one

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapFragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/buttonBar"
    class="com.myFactory.myApp.MySupportMapFragment"
    />

Yeah, That's all now the Google Map V2 can drag in the Navigating Drawer




回答2:


Hope this was the solution that you had implemented earlier

seekbar.setOnTouchListener(new ListView.OnTouchListener() 
{
    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
        int action = event.getAction();
        switch (action) 
        {
        case MotionEvent.ACTION_DOWN:
            // Disallow Drawer to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(true);
            break;

        case MotionEvent.ACTION_UP:
            // Allow Drawer to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(false);
            break;
        }

        // Handle seekbar touch events.
        v.onTouchEvent(event);
        return true;
    }
});


来源:https://stackoverflow.com/questions/24801813/google-map-v2-and-navigation-drawer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!