gpt4 book ai didi

java - Android Studio 预览来自 google map API 的 map 不会显示 map

转载 作者:行者123 更新时间:2023-12-02 09:49:15 25 4
gpt4 key购买 nike

我已通过向导创建了一个新项目,并选择了“Google map Activity ”。插入了我的 API key ,但没有 map 预览,只有灰屏显示 。还有一个名为“未知 fragment ”的警告,内容如下:

"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"

我在网上搜索了好几个小时,但找不到解决该问题的方法。如果有人可以,请告诉我,我将非常感激。

这是来自activity_maps.xml的代码

<?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" />

这是 MapsActivty.java 中的代码

>     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));
> }
> }

最佳答案

直到运行时, fragment 才会附加到 Activity 。 Android Studio 不知道您正在尝试预览哪个 fragment 。你收到的警告说明了一切。这不是问题,而是 Android Studio 设计器的限制。

关于java - Android Studio 预览来自 google map API 的 map 不会显示 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56435020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com