0

我正在尝试使用适用于 android v2 的谷歌地图。我按照以下说明进行操作:

https://developers.google.com/maps/documentation/android/start

我在(上述网页的)底部,上面写着“添加地图”。当我将以下代码复制并粘贴到我的 main.xml 中时:

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/map"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   class="com.google.android.gms.maps.MapFragment"/>

我在 Linearlayout 标记上看到一个错误,上面写着:“根元素之后的文档中的标记必须格式正确。”

这是 main.xml 的全部内容:

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

 <fragment xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/map"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   class="com.google.android.gms.maps.MapFragment"/>


 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="horizontal"
     android:padding="30dip">



    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="25dip"
        android:text="@string/welcome"
        android:textSize="24sp"/>

    <EditText
        android:id="@+id/editText1"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" 
        android:hint="@string/edit_location"/>

    <Button
        android:id="@+id/find_me_button"
        android:layout_weight="0"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/button_find_me"/>

    </LinearLayout>

为什么这不是格式正确的?

编辑:我尝试从 LinearLayout 中删除 "xmlns:android="http://schemas.android.com/apk/res/android" 但它没有任何区别。

4

1 回答 1

3

请试试这个:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="horizontal"
 android:padding="30dip">

 <fragment
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  class="com.google.android.gms.maps.MapFragment"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="25dip"
    android:text="@string/welcome"
    android:textSize="24sp"/>

<EditText
    android:id="@+id/editText1"
    android:layout_weight="1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" 
    android:hint="@string/edit_location"/>

<Button
    android:id="@+id/find_me_button"
    android:layout_weight="0"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/button_find_me"/>

</LinearLayout>

它可能会帮助你。

于 2013-02-19T06:28:57.987 回答