1.创建 自定义View MapContainer类
import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.RelativeLayout; import android.widget.ScrollView; public class MapContainer extends RelativeLayout { private ScrollView scrollView; public MapContainer(Context context) { super(context); } public MapContainer(Context context, AttributeSet attrs) { super(context, attrs); } public void setScrollView(ScrollView 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; } }
2更改布局
- <com.babyrun.mmsh.widget.MapContainer
- android:id="@+id/map_container"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <com.amap.api.maps2d.MapView
- android:id="@+id/map"
- android:layout_width="match_parent"
- android:layout_height="350dp" />
- </com.babyrun.mmsh.widget.MapContainer>
3.
- scrollView = (ScrollView) findViewById(R.id.scrollview);
- map_container = (MapContainer) findViewById(R.id.map_container);
- map_container.setScrollView(scrollView);