简体   繁体   English

Android Google地图上的Xml属性不适用于AndroidStudio

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

I'm creating a simple Android app with Google Maps. 我正在使用Google地图创建一个简单的Android应用。 I've this layout: 我有这个布局:

<?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 tell me: AndroidStudio告诉我:

Unexpected namespace prefix "map" found for tag fragment

and it marks all lines with "map" prefix as errors also if the code seem ok to me. 并且如果代码对我来说似乎也可以将带有“map”前缀的所有行标记为错误。 Infact deploying my app I can see that all map tags are working on my Android device. 实际部署我的应用程序,我可以看到所有地图标签都在我的Android设备上运行。

So I'm asking if it is only a small bug of AndroidStudio. 所以我问这是否只是AndroidStudio的一个小错误。

A little curiosity: using this layout instead AndroidStudio doesn't mark any error: 有点好奇:使用这个布局而不是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"
/>

It seems like xmlns:map="http://schemas.android.com/apk/res-auto" namespace declaration in your <FrameLayout> element doesnt carry downwards into <fragment> namespace. 看起来你的<FrameLayout>元素中的xmlns:map="http://schemas.android.com/apk/res-auto"名称空间声明不会向下进入<fragment>名称空间。 Your second example has the namespace declaration within the element that uses it ( <fragment> ) and Android Studio recognizes it immediately. 您的第二个示例在使用它的元素( <fragment> )中具有名称空间声明,Android Studio会立即识别它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM