gpt4 book ai didi

android - 谷歌地图 fragment 中的 SupportMapFragment 错误

转载 作者:行者123 更新时间:2023-11-29 17:01:13 25 4
gpt4 key购买 nike

旧版本应用程序使用MapView。我更改了SupportMapFragment错误。我知道如何解决这个问题。

Process: com.test.app, PID: 7847
android.view.InflateException: Binary XML file line #14: Error inflating class fragment

xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</FrameLayout>

fragment

public class MyFragment extends Fragment implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener {

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

View rootView = inflater.inflate(R.layout.fragment_map, null);

SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

buildGoogleApiClient();


return rootView;
}

构建.gradle

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services-location:10.2.0'
compile 'com.google.android.gms:play-services-maps:10.2.0'
compile 'se.emilsjolander:stickylistheaders:2.5.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
//compile 'com.google.firebase:firebase-messaging:10.2.0'


}

最佳答案

public class MapFragment extends Fragment implements OnMapReadyCallback {

SupportMapFragment mapFragment;

@Override
public void onMapReady(GoogleMap googleMap) {
LatLng sydney = new LatLng(-33.852, 151.211);
googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.map_fragment, container, false);
return view;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

关于android - 谷歌地图 fragment 中的 SupportMapFragment 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42855780/

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