Java 来自谷歌地图API的Android Studio预览地图赢得';不要显示地图

Java 来自谷歌地图API的Android Studio预览地图赢得';不要显示地图,java,android,google-maps-android-api-2,Java,Android,Google Maps Android Api 2,我通过向导创建了一个新项目,并选择了“谷歌地图活动”。插入了我的API密钥,但没有地图预览,只有一个灰色屏幕显示。还有一个名为Unknown fragments的警告,上面说: "A <fragment> tag allows a layout file to dynamically include different layouts at runtime. At layout editing time the specific layout to be used is not kn

我通过向导创建了一个新项目,并选择了“谷歌地图活动”。插入了我的API密钥,但没有地图预览,只有一个灰色屏幕显示。还有一个名为Unknown fragments的警告,上面说:

"A <fragment> tag allows a layout file to dynamically include different layouts at runtime. At layout editing time the specific layout to be used is not known. You can choose which layout you would like previewed while editing the layout.
- <fragment com.google.android.gms.maps.SupportMapFragment ...> (Pick Layout...)
 Do not warn about <fragment> tags in this session"

在运行时之前,片段不会附加到活动。Android Studio不知道您要预览的片段。你得到的警告说明了一切。这不是一个问题,而是Android Studio designer的一个限制。

你能发布你的片段和布局代码吗?你的问题不清楚。。。你是说你只是在Android Studio designer预览中看到一个灰色屏幕?您的编辑说,在您的设备上运行应用程序时,它可以工作。@GarrettManley,正如您所说:我在Android Studio designer预览中看到一个灰色屏幕,我可以在我的设备上运行它,它在我的设备上工作,当然,Android Studio中的预览仍然是灰色的。@TennysonChingombe,这是代码,默认情况下,GenerateEdit还表示“在版面编辑时,不知道要使用的特定版面。编辑版面时,您可以选择要预览的版面。”但我无法使其正常工作。我看过很多pleople的视频,他们在显示时没有问题,所以我认为这是可以做到的
<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsActivity"
    tools:layout="@layout/activity_maps" />
>     package com.example.android.myapplication;
>     
>     import android.support.v4.app.FragmentActivity;
>     import android.os.Bundle;
>     
>     import com.google.android.gms.maps.CameraUpdateFactory;
>     import com.google.android.gms.maps.GoogleMap;
>     import com.google.android.gms.maps.OnMapReadyCallback;
>     import com.google.android.gms.maps.SupportMapFragment;
>     import com.google.android.gms.maps.model.LatLng;
>     import com.google.android.gms.maps.model.MarkerOptions;
>     
>     public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
>     
>         private GoogleMap mMap;
>     
>         @Override
>         protected void onCreate(Bundle savedInstanceState) {
>             super.onCreate(savedInstanceState);
>             setContentView(R.layout.activity_maps);
>             // Obtain the SupportMapFragment and get notified when the map is ready to be used.
>             SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
>                     .findFragmentById(R.id.map);
>             mapFragment.getMapAsync(this);
>         }
>     
>         @Override
>         public void onMapReady(GoogleMap googleMap) {
>             mMap = googleMap;
>     
>             // Add a marker in Sydney and move the camera
>             LatLng sydney = new LatLng(-34, 151);
>             mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
>             mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
>         }
>     }