Android Studio Google Map V2片段呈现

我试图在Android Studio中编写Google Map V2的testing演示。 我遵循Androidhive Google Map V2的每一个步骤,或者更好,我认为我需要。

我使用相同的layout_main.xml

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <fragment android:id="@+id/map" android:name="com.google.android.gms.maps.MapFragment" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout> 

但我总是有相同的渲染问题:

渲染问题
<fragment>标签允许布局文件在运行时dynamic地包含不同的布局。 在布局编辑时,要使用的特定布局未知。 您可以在编辑布局时select您想要预览的布局…

我完全不知道有什么问题。 我忘记了什么吗? 我只需要在build.gradle中添加Google服务

 compile 'com.google.android.gms:play-services:4.4.52' 

我复制了演示中的清单,并更改了API密钥。

渲染问题
标签<fragment>允许布局文件在运行时dynamic包含不同的布局。 在布局编辑时,要使用的特定布局未知。 您可以在编辑布局时select您想要预览的布局…

这只是预览窗口,告诉你它不能显示<Fragment.../>标签的预览,因为它不知道你要放入什么types的片段。 你可以放心地忽略这个消息 – 当你运行它的时候,你的实际的应用程序将会很好地渲染这个片段(只要你正确的编码了)。

接受的答案是没有错的,但是没有帮助。

正如Dan所写,Android Studio(也是版本1.0)将不会显示地图。
地图需要一个API密钥和dynamic处理的代码,也许有一天我们会有,但到目前为止没有。
对于那些想要在布局预览中正确查看应用的用户,我有一个5分钟的解决scheme: 在这里输入图像说明

为了正确的发展,我还需要别的东西,而不是空白的背景。
我在地图顶部添加了覆盖和button,我真的需要在将元素放置在地图上的同时看到地图。
解决scheme很简单:
1.使用正在运行的地图制作应用程序的屏幕截图(Power + Volume Down)
2.下载屏幕截图并使用图像编辑器删除顶部和底部UI元素,这样您最终只会将地图本身作为图像。
3.将该图像导入到android studio drawable中
4.创build一个新的布局,将其命名为dummy_mapviewfragment ,只放入一个linearlayout和一个imageview
5.使imageview“填充”父母,并设置“src”到你刚才导入的裁剪图像
6.回到你的布局,把这个添加到你的Mapview Fragment xml中:

  tools:layout="@layout/dummy_mapviewfragment"/> 

就是这样,现在你将有一个非交互式的mapview片段显示一个真实的地图。
您的应用将看起来像在您的手机上。 如果在图像裁剪中出现错误,您可以通过将图像比例设置为“centerCrop”来“修复”图像,以便正确伸展。

更新:你可以得到一个截图,而不需要直接从Androidstudio内裁剪! 使它更方便;)

添加一个虚拟布局“@android:layout / simple_gallery_item”为:

 <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="317dp" android:layout_height="385dp" android:id="@+id/map" tools:context="com.example.XYZ.googlemaps.MapsActivity" android:name="com.google.android.gms.maps.SupportMapFragment" tools:layout="@android:layout/simple_gallery_item"/>