Android docs声明在 XML 中创建 MapFragment 的最简单方法如下:
<fragment
class="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
如果以这种方式创建 MapFragment,如何将精简模式设置为 true
?
最佳答案
显然,将 map fragment 作为子项添加到父容器时存在错误。我通过首先像这样更改父容器的命名空间来解决这个问题:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto">
现在,问题是 fragment 中标记了一个无效错误(为标记 fragment 找到意外的命名空间前缀“map”
)。在 Android Studio 中解决这个问题的最简单方法是添加 tools:ignore="MissingPrefix
。这是我为该 fragment 完成的 XML 代码:
<fragment
class="com.google.android.gms.maps.MapFragment"
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="300dp"
tools:ignore="MissingPrefix"
map:liteMode="true"/>
关于android - 如何在 XML 中为 Android Google MapFragment 设置精简模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27978683/