【问题标题】:Adding a Google maps on my fragment在我的片段上添加谷歌地图
【发布时间】:2013-08-17 00:54:25
【问题描述】:

我正在尝试在新片段中添加 Google 地图。但我得到这个错误:

08-16 16:58:37.334:E/AndroidRuntime(15409):致命异常:主要 08-16 16:58:37.334: E/AndroidRuntime(15409): android.view.InflateException:二进制 XML 文件第 2 行:错误 膨胀类片段 08-16 16:58:37.334: E/AndroidRuntime(15409): 在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710) 08-16 16:58:37.334: E/AndroidRuntime(15409): 在 android.view.LayoutInflater.inflate(LayoutInflater.java:467)

这是启动片段的代码:

    Fragment fragment1 = new MapsFragment();
    //fragment.setArguments(arguments);
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
    fragmentTransaction.replace(R.id.content_frame, fragment1);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();

这是我的 MapsFragment 的代码:

import com.rss.main.MainActivity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MapsFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        LayoutInflater mInflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        View view = (View) mInflater.inflate(R.layout.maps_view, null);

//      MainActivity.setShareButtonToVisible();
//      MainActivity.setElevatorButtonToInVisible();

        return view;
    }

    @Override
    public void onDestroyView() {
        MainActivity.setShareButtonToInVisible();
        super.onDestroyView();
    }


}

这是我的 maps_view.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"
          android:name="com.google.android.gms.maps.MapFragment"/>

问题出在哪里?

谢谢

【问题讨论】:

标签: android android-maps android-maps-v2


【解决方案1】:

您的 Mainactivty 应该扩展 FragmentActivity 检查google play服务是否可用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    • 2017-08-16
    • 2016-03-25
    相关资源
    最近更新 更多