一.首先解决MapView与ScrollView滑动冲突问题
解决地图在主scrollview中滑动冲突的问题由于MapView被定义成final class,所以只能在容器中操作了
public class MapContainer extends RelativeLayout{
private NestedScrollView scrollView;
public MapContainer(Context context) {
super(context);
}
public MapContainer(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setScrollView(NestedScrollView scrollView) {
this.scrollView = scrollView;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_UP) {
scrollView.requestDisallowInterceptTouchEvent(false);
} else {
scrollView.requestDisallowInterceptTouchEvent(true);
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return true;
}
}
用法
1.布局中
<xxx.widgets.MapContainer
android:id="@+id/id_map_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.amap.api.maps.MapView
android:id="@+id/id_main_map"
android:layout_width="match_parent"
android:layout_height="240dp" />
</xxx.widgets.MapContainer>
2.代码中
mScrollView = rootView.findViewById(R.id.id_main_scroll);//最外层包裹ScrollView
mapContainer = rootView.findViewById(R.id.id_map_container);
mapContainer.setScrollView(mScrollView);
二.解决SwipeRefreshLayout下拉刷新与ScrollView滑动冲突问题
1.将ScrollView换成
android.support.v4.widget.NestedScrollView
2.修改MapContainer做想用修改 上面是修改后的 可直接用