我在ScrollView中有一个Google Maps mapView。它工作正常,除了滚动我在底部和顶部有一些丑陋的黑色背景。
以下是该问题的视频:
https://www.youtube.com/watch?v=wLla7nS6Ehc&feature=youtu.be
为了解决这个问题,我将Map包装在FrameLayout中并使其比实际容器更大,这解决了问题,除了现在我再也看不到Google水印了。我尝试使用底部填充,但使用填充黑色图案再次显示,但这次只在底部。
是否可以将带有Google地图水印字体和样式的TextView放在FrameLayout中作为解决方法?如果我这样做,我是否违反了服务条款?
这是我修复的xml:
<FrameLayout
android:id="@+id/map_view_container"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@+id/location"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/full_margin"
android:background="@color/transparent">
<com.google.android.gms.maps.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_gravity="center"
android:background="@color/off_white"
map:mapType="normal" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent" />
</FrameLayout>
编辑:片段代码:
公共类MapFragment扩展了Fragment 实现View.OnClickListener, com.google.android.gms.maps.OnMapReadyCallback {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_business_home, container, false);
final Bundle mapViewSavedInstanceState = savedInstanceState != null ? savedInstanceState.getBundle("mapViewSaveState") : null;
initializeViewComponents(rootView, mapViewSavedInstanceState);
return rootView;
}
private void initializeViewComponents(View rootView, Bundle savedInstanceState) {
scrollView = (ScrollView) rootView.findViewById(R.id.scroll_view);
mapView = (MapView) rootView.findViewById(R.id.map_view);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
MapsInitializer.initialize(this.getActivity());
this.map = googleMap;
// Gets to GoogleMap from the MapView and does initialization stuff
map.getUiSettings().setMyLocationButtonEnabled(true);
map.getUiSettings().setAllGesturesEnabled(false);
map.setMyLocationEnabled(true);
onAsyncLoad();
}
@Override
public void onResume() {
if (mapView != null) {
mapView.onResume();
}
super.onResume();
}
@Override
public void onLowMemory() {
if (mapView != null) {
mapView.onLowMemory();
}
super.onLowMemory();
}
public void onSaveInstanceState(Bundle outState) {
Log.i(TAG, "SAVING TO INSTANCE STATE");
//This MUST be done before saving any base class variables
final Bundle mapViewSaveState = new Bundle(outState);
if (mapView != null) { // May be null after onDestroView
mapView.onSaveInstanceState(mapViewSaveState);
outState.putBundle("mapViewSaveState", mapViewSaveState);
}
}