及成果Googlemap的同学都知道具体的套路,这里不是将Googlemap怎么继承而是将一个冲突。
scrollView可以上下滑动,Googlemap可以上下左右滑动,so i have a 冲突。
第一步:自定义 CustomSupportMapFragment extends SupportMapFragment
不叨叨直接撸码。
public class CustomSupportMapFragment extends SupportMapFragment {
private OnTouchListener mListener;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View layout = super.onCreateView(inflater, parent, savedInstanceState);
TouchableWrapper frameLayout = new TouchableWrapper(getActivity());
frameLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent));
if (layout != null && layout instanceof ViewGroup) {
((ViewGroup) layout).addView(frameLayout,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
return layout;
}
public void setListener(OnTouchListener listener) {
mListener = listener;
}
public interface OnTouchListener {
void onTouch();
}
public class TouchableWrapper extends FrameLayout {
public TouchableWrapper(Context context) {
super(context);
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mListener.onTouch();
break;
case MotionEvent.ACTION_UP:
mListener.onTouch();
break;
}
return super.dispatchTouchEvent(event);
}
}
}
第二步:xml布局,根据你的业务来。
<fragment
android:id="@+id/fragment_map"
android:layout_width="match_parent"
android:layout_marginTop="11dp"
android:layout_height="145dp" android:name="com.setvishero.proapp.CustomViews.CustomSupportMapFragment" />
第三部:Java代码
主要是nsv_claim.requestDisallowInterceptTouchEvent(true),这个方法的作用是要求不允许拦截触摸事件,true就不拦截,所以说map想怎么滑动就怎么滑动。