问题
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