如何在XML中为Android Google MapFragment制作set lite模式?

Joh*_*nny 2 xml android google-maps

Android的文档指出,最简单的方法来创建一个MapFragment在XML是像这样:

<fragment
    class="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)

如果以这种方式创建MapFragment,如何将lite模式设置为true

Joh*_*nny 8

显然,将地图片段作为子容器添加到父容器时会出现错误.我通过首先更改父容器的命名空间来解决这个问题,如下所示:

<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">
Run Code Online (Sandbox Code Playgroud)

现在,问题是片段(Unexpected namespace prefix "map" found for tag fragment)中标记了无效错误.在Android Studio中克服此问题的最简单方法是添加tools:ignore="MissingPrefix.这是我完成的片段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"/>
Run Code Online (Sandbox Code Playgroud)


Ver*_*rma 5

在 xml

   <fragment mlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:name="com.google.android.gms.maps.MapFragment"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        map:cameraZoom="13"
        map:mapType="normal"
        map:liteMode="true"/>
Run Code Online (Sandbox Code Playgroud)

在 GoogleMapOptions 对象中

GoogleMapOptions options = new GoogleMapOptions().liteMode(true);
Run Code Online (Sandbox Code Playgroud)