解决MapView,ScrollView,SwipeRefreshLayout滑动冲突问题

一.首先解决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做想用修改 上面是修改后的 可直接用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值