我在xml文件中初始化MapFragment时遇到问题,我不明白它为什么会以某种方式工作,而不是另一种方式。
在开发过程中,我首先在我的主要活动中只有一个MapFragment。这很好用:
<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:cameraTargetLat="22.320542"
map:cameraTargetLng="114.185715"
map:mapType="normal"
map:cameraZoom="11"
/>
以合适的缩放级别打开我的地图,专注于香港。但是现在我在布局中添加了一些元素,而且我不能再使用map:
名称空间了。它被Eclipse拒绝。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TableLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/current" />
<TextView
android:id="@+id/textCurrent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/forecast" />
<TextView
android:id="@+id/textForecast"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
</LinearLayout>
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>
</LinearLayout>
现在我找到了从代码设置地图选项的方法,例如here和here - 这不是真正的问题。这不是我希望解决它的方式,但它是可以接受的。我大多试图理解为什么第二种方式不起作用?地图名称空间在开头声明,同时显示整个xml中显然存在的android名称空间。
答案 0 :(得分:3)
这看起来像工具中的错误。我提交了an issue about it。您可能想要将其加星标记或以其他方式安排跟踪它以查看它是否真的是一个错误,如果它被修复等等。
答案 1 :(得分:0)
看起来像Eclipse中的一个错误 - 通过清理和重建项目来解决。