【发布时间】:2016-07-20 19:26:59
【问题描述】:
我正在观察 Google 地图的意外行为。 问题是地图使用支持地图片段从顶部和底部区域进行裁剪, 如果我使用全屏,则地图完全可见,如图 1 所示,但如果我应用地图片段高度或重量属性,则地图不完全可见,如图 2 所示。
图片1的布局xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.paki.venturedive.awtest.MapsActivity" />
图片2的布局xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
tools:context="com.paki.venturedive.awtest.MapsActivity" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello world"
android:layout_weight="0.4" />
Java 代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
在图2中,我(用户将)无法看到格陵兰地区上方的北冰洋,同样底部区域将丢失,如图3所示。
有人遇到过这个问题吗,或者有人知道如何解决吗?
任何参考链接或提示将不胜感激。
【问题讨论】:
-
发布您的 xml 。设置高度和宽度的代码。
-
@SagarNayak 问题已编辑。
-
当您将其权重设置为 0.6 时,线性布局将仅提供 60% 的空间来映射片段。告诉我你为什么要减肥。你到底想要什么?
-
我正在给予权重,因为应用程序要求在 60% 的区域上显示地图。虽然地图是可滚动的并且它可以滚动,所以它应该显示完整的地图,正如我们在 maps.google.com 上看到的那样
-
我不明白。您希望地图以 60% 的区域显示在屏幕上。你明白了。然后呢?
标签: android google-maps google-maps-android-api-2 supportmapfragment