map与recycleView拼接于同一个页面,类似高德地图效果。
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
app:layout_constraintTop_toBottomOf="@id/tvAddress">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
android:paddingBottom="@dimen/dp_100">
<com.amap.api.maps2d.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="220dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/mapContainer"
android:nestedScrollingEnabled="false"
android:paddingBottom="@dimen/dp_10"
android:scrollbars="none"
tools:listitem="@layout/recycle_store" />
</RelativeLayout>
</ScrollView>
scrollview与地图冲突,滑动地图时,出现卡顿情况 。
自定义控件
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;
}
}
给map包裹加一件衣服
<com.ss.kitchens.mvp.ui.widget.MapContainer
android:id="@+id/mapContainer"
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="220dp" />
</com.ss.kitchens.mvp.ui.widget.MapContainer>
然后再Activity里面添加
mapContainer.setScrollView(scrollView);
再次运行,即可。