对我来说,添加一个透明的 ImageView 并没有帮助完全去除黑色面具。滚动时地图的顶部和底部仍然显示黑色蒙版。
所以它的解决方案,我在这个答案中发现了一个小的变化。我补充说,
android:layout_marginTop="-100dp"
android:layout_marginBottom="-100dp"
到我的地图片段,因为它是垂直滚动视图。所以我的布局现在看起来是这样的:
<RelativeLayout
android:id="@+id/map_layout"
android:layout_width="match_parent"
android:layout_height="300dp">
<fragment
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-100dp"
android:layout_marginBottom="-100dp"
android:name="com.google.android.gms.maps.MapFragment"/>
<ImageView
android:id="@+id/transparent_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@color/transparent" />
</RelativeLayout>
requestDisallowInterceptTouchEvent(true)
为了解决我为主 ScrollView设置的问题的第二部分。当用户触摸透明图像并移动时,我禁用了透明图像上的触摸,MotionEvent.ACTION_DOWN
以便MotionEvent.ACTION_MOVE
地图片段可以接受触摸事件。
ScrollView mainScrollView = (ScrollView) findViewById(R.id.main_scrollview);
ImageView transparentImageView = (ImageView) findViewById(R.id.transparent_image);
transparentImageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
mainScrollView.requestDisallowInterceptTouchEvent(true);
// Disable touch on transparent view
return false;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
mainScrollView.requestDisallowInterceptTouchEvent(false);
return true;
case MotionEvent.ACTION_MOVE:
mainScrollView.requestDisallowInterceptTouchEvent(true);
return false;
default:
return true;
}
}
});
这对我有用。希望对你有帮助。。