簡體   English   中英

Android Google地圖上的Xml屬性不適用於AndroidStudio

[英]Xml attributes on Android Google Maps doesn't work with AndroidStudio

我正在使用Google地圖創建一個簡單的Android應用。 我有這個布局:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/root"
android:background="@android:color/transparent">

<fragment
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:name="com.google.android.gms.maps.MapFragment"
    android:id="@+id/map2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
     map:cameraBearing="112.5"
    map:cameraTargetLat="45.438122"
    map:cameraTargetLng="12.318221"
    map:cameraTilt="30"
    map:cameraZoom="18"
    map:mapType="normal"
    map:uiCompass="false"
    map:uiRotateGestures="true"
    map:uiScrollGestures="true"
    map:uiTiltGestures="false"
    map:uiZoomControls="true"
    map:uiZoomGestures="true"
    />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:src="@drawable/map"
    android:layout_gravity="left|top"
    android:layout_alignParentLeft="false"
    android:layout_alignParentTop="false"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true" />
 </FrameLayout>

AndroidStudio告訴我:

Unexpected namespace prefix "map" found for tag fragment

並且如果代碼對我來說似乎也可以將帶有“map”前綴的所有行標記為錯誤。 實際部署我的應用程序,我可以看到所有地圖標簽都在我的Android設備上運行。

所以我問這是否只是AndroidStudio的一個小錯誤。

有點好奇:使用這個布局而不是AndroidStudio沒有標記任何錯誤:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraBearing="112.5"
map:cameraTargetLat="45.438122"
map:cameraTargetLng="12.318221"
map:cameraTilt="30"
map:cameraZoom="18"
map:mapType="normal"
map:uiCompass="false"
map:uiRotateGestures="true"
map:uiScrollGestures="true"
map:uiTiltGestures="false"
map:uiZoomControls="true"
map:uiZoomGestures="true"
/>

看起來你的<FrameLayout>元素中的xmlns:map="http://schemas.android.com/apk/res-auto"名稱空間聲明不會向下進入<fragment>名稱空間。 您的第二個示例在使用它的元素( <fragment> )中具有名稱空間聲明,Android Studio會立即識別它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM