地图属性在xml文件中不工作,尽管有真正的代码



在我运行地图应用程序时没有错误。不幸的是,当我在xml片段中添加一些属性时,它没有显示任何结果。我不知道为什么。我使用minSdkVersion=17和targetSdkVersion=21。请帮帮我。

这是Main.java

public class MainActivity extends FragmentActivity {
    private static final int GPS_ERRORDIALOG_REQUEST = 9001;
    GoogleMap gmap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(servicesOk())
        {
            setContentView(R.layout.activity_map);
        if(InitMap())
        {
            Toast.makeText(this, "Ready to Map !", Toast.LENGTH_SHORT).show();
        }
        else
        {
            Toast.makeText(this, "Map not available !", Toast.LENGTH_SHORT).show();
        }
        }
        else{
    setContentView(R.layout.activity_main);
            }
    }
    public boolean servicesOk(){
        int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if(isAvailable == ConnectionResult.SUCCESS){
            return true;
        }
        else if(GooglePlayServicesUtil.isUserRecoverableError(isAvailable))
        {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
            dialog.show();
        }
        else{
            Toast.makeText(this, "Cannot connect to the Google Play Services",
                    Toast.LENGTH_SHORT).show();
        }
        return false;
    }
    private boolean InitMap(){
        if(gmap== null)
        {
            SupportMapFragment mapFragment = 
        (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        gmap = mapFragment.getMap();
        }
        return(gmap != null);
    }

这是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"
  android:name="com.google.android.gms.maps.SupportMapFragment"
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  map:cameraBearing="112.5"
  map:cameraTargetLat="-33.796923"
  map:cameraTargetLng="150.922433"
  map:cameraTilt="30"
  map:cameraZoom="13"
  map:mapType="satellite"
  map:uiCompass="false"
  map:uiRotateGestures="true"
  map:uiScrollGestures="false"
  map:uiTiltGestures="true"
  map:uiZoomControls="false"
  map:uiZoomGestures="true"/>

这是logcat文件

09-11 13:19:05.868: I/dalvikvm(19918): Could not find method andriod.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
09-11 13:19:05.868: W/dalvikvm(19918): VFY: unable to resolve virtual method 227: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
09-11 13:19:05.868: D/dalvikvm(19918): VFY: replacing opcode 0x6e at 0x00c2
09-11 13:19:05.868: I/dalvikvm(19918): DexOpt: access denied from Lcom/google/android/gms/common/GooglePlayServicesUtil; to field Landroid/app/Notification;.extras
09-11 13:19:05.868: W/dalvikvm(19918): VFY: unable to resolve instance field 17
09-11 13:19:05.868: D/dalvikvm(19918): VFY: replacing opcode 0x54 at 0x00e1
09-11 13:19:05.868: E/dalvikvm(19918): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
09-11 13:19:05.868: W/dalvikvm(19918): VFY: unable to resolve check-cast 25 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
09-11 13:19:05.868: D/dalvikvm(19918): VFY: replacing opcode 0x1f at 0x000e
09-11 13:19:05.878: I/dalvikvm(19918): Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzh
09-11 13:19:05.878: W/dalvikvm(19918): VFY: unable to resolve virtual method 481: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
09-11 13:19:05.878: D/dalvikvm(19918): VFY: replacing opcode 0x6e at 0x000b
09-11 13:19:06.058: I/zzy(19918): Making Creator dynamically
09-11 13:19:06.289: E/dalvikvm(19918): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.kf.a
09-11 13:19:06.289: W/dalvikvm(19918): VFY: unable to resolve check-cast 35 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/kf;
09-11 13:19:06.289: D/dalvikvm(19918): VFY: replacing opcode 0x1f at 0x0010
09-11 13:19:06.289: I/dalvikvm(19918): Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.kf.a
09-11 13:19:06.289: W/dalvikvm(19918): VFY: unable to resolve virtual method 460: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
09-11 13:19:06.289: D/dalvikvm(19918): VFY: replacing opcode 0x6e at 0x000d
09-11 13:19:06.289: I/dalvikvm(19918): Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.kf.b
09-11 13:19:06.289: W/dalvikvm(19918): VFY: unable to resolve virtual method 166: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
09-11 13:19:06.289: D/dalvikvm(19918): VFY: replacing opcode 0x6e at 0x0201
09-11 13:19:06.289: I/dalvikvm(19918): DexOpt: access denied from Lcom/google/android/gms/common/kf; to field Landroid/app/Notification;.extras
09-11 13:19:06.289: W/dalvikvm(19918): VFY: unable to resolve instance field 34
09-11 13:19:06.289: D/dalvikvm(19918): VFY: replacing opcode 0x54 at 0x0220
09-11 13:19:06.309: D/ChimeraCfgMgr(19918): Loading module com.google.android.gms.maps from APK /data/data/com.google.android.gms/app_chimera/chimera-module-root/module-bbaa4a2038efe5e7bc9f6f2289df36321375dd10/MapsModule.apk
09-11 13:19:06.309: D/ChimeraModuleLdr(19918): Loading module APK /data/data/com.google.android.gms/app_chimera/chimera-module-root/module-bbaa4a2038efe5e7bc9f6f2289df36321375dd10/MapsModule.apk
09-11 13:19:06.399: D/ChimeraFileApk(19918): Primary ABI of requesting process is armeabi-v7a
09-11 13:19:06.399: D/ChimeraFileApk(19918): Classloading successful, but code may not be optimized. It will either run in fallback (interpreted mode) or the odex has been found and isDexOptNeeded is misreporting a failure.
09-11 13:19:06.579: I/Google Maps Android API(19918): Google Play services client version: 7895000
09-11 13:19:06.589: I/Google Maps Android API(19918): Google Play services package version: 7899034
09-11 13:19:06.619: E/dalvikvm(19918): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.jy.a
09-11 13:19:06.619: W/dalvikvm(19918): VFY: unable to resolve check-cast 14 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/jy;
09-11 13:19:06.619: D/dalvikvm(19918): VFY: replacing opcode 0x1f at 0x0010
09-11 13:19:06.619: I/dalvikvm(19918): Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.jy.a
09-11 13:19:06.619: W/dalvikvm(19918): VFY: unable to resolve virtual method 126: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
09-11 13:19:06.619: D/dalvikvm(19918): VFY: replacing opcode 0x6e at 0x000d
09-11 13:19:06.859: D/dalvikvm(19918): GC_CONCURRENT freed 474K, 14% free 8981K/10360K, paused 56ms+1ms, total 85ms
09-11 13:19:06.889: I/e(19918): Token loaded from file. Expires in: 259464689 ms.
09-11 13:19:06.889: I/e(19918): Scheduling next attempt in 259164 seconds.
09-11 13:19:07.019: D/dalvikvm(19918): GC_CONCURRENT freed 338K, 12% free 9155K/10396K, paused 5ms+2ms, total 21ms
09-11 13:19:07.019: D/dalvikvm(19918): WAIT_FOR_CONCURRENT_GC blocked 10ms
09-11 13:19:07.260: D/AbsListView(19918): Get MotionRecognitionManager
09-11 13:19:07.330: D/AbsListView(19918): onVisibilityChanged() is called, visibility : 8
09-11 13:19:07.330: D/AbsListView(19918): unregisterIRListener() is called 
09-11 13:19:07.330: D/AbsListView(19918): onVisibilityChanged() is called, visibility : 8
09-11 13:19:07.330: D/AbsListView(19918): unregisterIRListener() is called 
09-11 13:19:07.390: E/dalvikvm(19918): adjustAdaptiveCoef max=4194304, min=1048576, ut=568
09-11 13:19:07.390: D/dalvikvm(19918): GC_CONCURRENT freed 162K, 11% free 9406K/10564K, paused 5ms+4ms, total 55ms
09-11 13:19:07.390: D/dalvikvm(19918): WAIT_FOR_CONCURRENT_GC blocked 39ms
09-11 13:19:07.710: D/AbsListView(19918): onVisibilityChanged() is called, visibility : 0
09-11 13:19:07.710: D/AbsListView(19918): unregisterIRListener() is called 
09-11 13:19:07.880: E/dalvikvm(19918): adjustAdaptiveCoef max=6291456, min=1572864, ut=368
09-11 13:19:07.880: D/dalvikvm(19918): GC_CONCURRENT freed 577K, 14% free 9778K/11260K, paused 4ms+137ms, total 165ms
09-11 13:19:07.980: W/ActivityThread(19918): ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader());
09-11 13:19:08.070: D/AbsListView(19918): onVisibilityChanged() is called, visibility : 4
09-11 13:19:08.070: D/AbsListView(19918): unregisterIRListener() is called 
09-11 13:19:08.100: D/AbsListView(19918): onVisibilityChanged() is called, visibility : 0
09-11 13:19:08.100: D/AbsListView(19918): unregisterIRListener() is called 
09-11 13:19:08.261: D/libEGL(19918): loaded /system/lib/egl/libGLES_hawaii.so
09-11 13:19:08.271: D/(19918): mem_init ++
09-11 13:19:08.271: D/(19918): gHwMemAllocator client 3
09-11 13:19:08.271: D/(19918): **** Using ION allocator ****
09-11 13:19:08.271: D/(19918): registered SIGUSR1[10] for pid[19918]
09-11 13:19:08.271: D/(19918): HwMemAllocatorImpl Static Counters 0 0
09-11 13:19:08.271: D/(19918): HwMemAllocatorImpl[49306dcc] totalDeviceAllocSize[0] totalFree[0] maxFree[0] in numSlabs[0]
09-11 13:19:08.271: D/(19918): mem_init 49306dcc--
09-11 13:19:08.271: D/ION(19918): config: version(0x10000) secure(0xf000) 256M(0x22d) fast(0x608) hwwr(0x608)
09-11 13:19:08.291: D/MM_DEVICE(19918): Waiting for mm thread to come up
09-11 13:19:08.291: D/MM_DEVICE(19918): mm_device_thread starting
09-11 13:19:08.301: D/HAWAII_EGL(19918): eglCreateContext() config: 18 context: 0x4c123b28, VC context 1, Thread 19918
09-11 13:19:08.301: D/HAWAII_EGL(19918): Set SWAP INTERVAL 0
09-11 13:19:08.301: D/HAWAII_EGL(19918): eglCreateWindowSurface() surface: 0x4c123b78, VC surface: 1, Thread: 19918
09-11 13:19:08.301: D/HAWAII_EGL(19918): eglMakeCurrent(0x4c123b28, 0x4c123b78, 0x4c123b78) Thread: 19918
09-11 13:19:08.311: D/OpenGLRenderer(19918): Enabling debug mode 0
09-11 13:19:08.321: D/AbsListView(19918): unregisterIRListener() is called 
09-11 13:19:08.481: D/HAWAII_EGL(19918): eglCreateContext() config: 13 context: 0x48e71a88, VC context 2, Thread 19989
09-11 13:19:08.481: D/HAWAII_EGL(19918): Set SWAP INTERVAL 0
09-11 13:19:08.501: D/HAWAII_EGL(19918): eglCreateWindowSurface() surface: 0x48e0c310, VC surface: 2, Thread: 19989
09-11 13:19:08.501: D/HAWAII_EGL(19918): eglMakeCurrent(0x48e71a88, 0x48e0c310, 0x48e0c310) Thread: 19989

尝试使用FrameLayout代替Fragment并将android:name="com.google.android.gms.maps.SupportMapFragment"更改为class="com.google.android.gms.maps.SupportMapFragment"

在活动:

        _mapFrag = new SupportMapFragment();
        FragmentTransaction transaction = getSupportFragmentManager().BeginTransaction();
        transaction.Replace(Resource.Id.map, _mapFrag);
        transaction.Commit();

相关内容

最新更新