旧版本的应用程序使用MapView
。我改变了SupportMapFragment
错误。我知道如何解决这个问题。谷歌地图SupportMapFragment错误中的片段
过程:com.test.app,PID:7847
android.view.InflateException:二进制XML文件行#14:错误 充气类片段
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>
片段
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;
}
的build.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'
}
应用上下文来使用这些工具的片段指向正确的活动:上下文属性 –
我都用过,但没有奏效@Bradley威尔逊 –
使用getActivity()getSupportFragmentManager()代替 –