二进制XML文件第1行:夸大类片段的错误Xamarin Android中的Google Maps错误

问题描述 投票:0回答:1

我在SetContentView(Resource.Layout.activity_main)上出现问题标题的错误;当我运行该应用程序时。

我有两个XML文件。 include_main.xml包含地图片段所在的框架布局。使用属性“ class”给我这个错误-“缺少Android XML名称空间;您的属性将被解释为自定义属性”。如果我将类更改为android:name,它将摆脱该错误,但是我仍然遇到二进制xml文件错误。如果我完全取出地图片段代码,则该应用程序将完全正常运行。

include_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rootView"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/ashGrey">

        <fragment 
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          class="com.google.android.gms.maps.SupportMapFragment" />


        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?android:attr/actionBarSize"
            android:id="@+id/mainToolbar"/>

        <LinearLayout
           android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="70dp">
                <FrameLayout
                android:id="@+id/frameLocations"
                android:layout_width="match_parent"
                android:layout_height="90dp"
                android:background="@drawable/roundedEdges">
                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_height="match_parent"
                        android:layout_width="match_parent">
                            <RelativeLayout 
                                android:layout_height="0dp"
                                android:layout_width="match_parent"
                                android:clickable="true"
                                android:layout_weight="0.5"
                                android:id="@+id/layoutPickup">

                                    <ImageView
                                        android:layout_height="8dp"
                                        android:layout_width="8dp"
                                        android:src="@drawable/greenball"
                                        android:layout_centerVertical="true"
                                        android:layout_marginLeft="10dp"/>

                                    <TextView 
                                        android:id="@+id/pickupLocationText"
                                        android:layout_height="wrap_content"
                                        android:layout_width="match_parent"
                                        android:text="Pickup Location"
                                        android:layout_centerVertical="true"
                                        android:layout_marginLeft="30dp"
                                        android:maxLines="2"
                                        android:gravity="center_vertical"
                                        android:layout_marginRight="36dp"/>

                                    <RadioButton
                                        android:id="@+id/DestinationRadio"
                                        android:layout_height="wrap_content"
                                        android:layout_width="wrap_content"
                                        android:layout_gravity="end"
                                        android:layout_alignParentRight="true"
                                        android:layout_centerVertical="true"
                                        android:layout_marginRight="10dp"
                                    />

                                    <View
                                        android:layout_height="1dp"
                                        android:layout_width="match_parent"
                                        android:layout_gravity="end"
                                        android:layout_alignParentBottom="true"
                                        android:background="@color/ashGrey"
                                    /> 
                            </RelativeLayout>
                            <RelativeLayout 
                                android:layout_height="0dp"
                                android:layout_width="match_parent"
                                android:clickable="true"
                                android:layout_weight="0.5"
                                android:id="@+id/layoutDestination">
                                    <ImageView
                                        android:layout_height="8dp"
                                        android:layout_width="8dp"
                                        android:src="@drawable/redball"
                                        android:layout_centerVertical="true"
                                        android:layout_marginLeft="10dp" 
                                    />

                                    <TextView 
                                        android:id="@+id/destinationText"
                                        android:layout_height="wrap_content"
                                        android:layout_width="match_parent"
                                        android:text="Destination"
                                        android:layout_centerVertical="true"
                                        android:layout_marginLeft="30dp"
                                        android:maxLines="2"
                                        android:gravity="center_vertical"
                                        android:layout_marginRight="36dp"/>


                                    <RadioButton
                                        android:id="@+id/DestinationRadio"
                                        android:layout_height="wrap_content"
                                        android:layout_width="wrap_content"
                                        android:layout_gravity="end"
                                        android:layout_alignParentRight="true"
                                        android:layout_centerVertical="true"
                                        android:layout_marginRight="10dp"
                                    />

                            </RelativeLayout>
                    </LinearLayout>
                </FrameLayout>
        </LinearLayout>

        <RelativeLayout
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:clickable="true"
            android:id="@+id/myLocation"
            android:layout_gravity="center | right"
            android:background="@drawable/roundedEdges"
            android:layout_marginRight="16dp">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:tint="@color/colorAccent"
                android:padding="5dp"
                android:src="@mipmap/ic_my_location_black_48dp"/>
        </RelativeLayout>
    </FrameLayout>
</android.support.design.widget.CoordinatorLayout>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawerLayout"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:layout_height="match_parent"
         android:layout_width="match_parent"
         android:orientation="vertical"
        >
        <include
            layout="@layout/include_main">
        </include>

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navView"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:layout_gravity="start"
        app:headerLayout="@layout/navHeader"
        />
</android.support.v4.widget.DrawerLayout>

Main_Activity.cs

using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using Firebase;
using Firebase.Database;
using Android.Views;
using Android.Gms.Maps;

namespace Semoto
{
    [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = false)]
    public class MainActivity : AppCompatActivity,  IOnMapReadyCallback
    {
        FirebaseDatabase test;
        Android.Support.V4.Widget.DrawerLayout drawerLayout;
        Android.Support.V7.Widget.Toolbar mainToolbar;
        GoogleMap mainMap;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
            ConnectControl();

            //SupportMapFragment mapFragment = (SupportMapFragment)SupportFragmentManager.FindFragmentById(Resource.Id.map);
            //mapFragment.GetMapAsync(this);
            SupportMapFragment _mapFragment = (SupportMapFragment)SupportFragmentManager.FindFragmentById(Resource.Id.map);;
            if (_mapFragment == null)
            {
                GoogleMapOptions mapOptions = new GoogleMapOptions()
                    .InvokeRotateGesturesEnabled(true)
                    .InvokeScrollGesturesEnabled(true)
                    .InvokeCompassEnabled(true)
                    .InvokeAmbientEnabled(true)
                    .InvokeMapType(GoogleMap.MapTypeNormal)
                    .InvokeZoomControlsEnabled(true)
                    .InvokeCompassEnabled(true);

                _mapFragment = SupportMapFragment.NewInstance(mapOptions);

                Android.Support.V4.App.FragmentTransaction fragTx = SupportFragmentManager.BeginTransaction();
                fragTx.Add(Resource.Id.map, _mapFragment, "map");
                fragTx.Commit();

                _mapFragment.GetMapAsync(this);
            }
        }

        /*public override bool OnCreateOptionsMenu(IMenu menu)
        {
            this.MenuInflater.Inflate(Resource.Menu.sideMenuBar, menu);
            return base.OnCreateOptionsMenu(menu);
        }
        public override bool OnCreateOptionsMenu(IMenu menu)
    {
        this.MenuInflater.Inflate(Resource.Menu.Testing_New_List, menu);
        return base.OnCreateOptionsMenu(menu);
    }
         */

        void ConnectControl()
        {
            drawerLayout = (Android.Support.V4.Widget.DrawerLayout)FindViewById(Resource.Id.drawerLayout);
            mainToolbar = (Android.Support.V7.Widget.Toolbar)FindViewById(Resource.Id.mainToolbar);
            SetSupportActionBar(mainToolbar);
            SupportActionBar.Title = "Where are you heading?";
            //Android.Support.V7.App.ActionBar actionBar = SupportActionBar;
            //ActionBar.SetDisplayHomeAsUpEnabled(true);
            //ActionBar.SetHomeAsUpIndicator(Resource.Drawable.abc_ic_star_half_black_36dp);
        }

        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            switch (item.ItemId)
            {
                case Android.Resource.Id.Home:
                    drawerLayout.OpenDrawer((int)GravityFlags.Left);
                    return true;

                default:
                    return base.OnOptionsItemSelected(item);
            }
        }

        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }

        public void OnMapReady(GoogleMap googleMap)
        {
            mainMap = googleMap;
        }
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.masslabs.semoto" android:installLocation="auto">
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="28" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="com.masslabs.semoto.permission.MAPS_RECEIVE" />
  <permission android:name="com.masslabs.semoto.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
  <uses-feature android:glEsVersion="0x00020000" android:required="true" />
  <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme" android:name="android.app.Application" android:debuggable="true">
    <activity android:label="@string/app_name" android:theme="@style/AppTheme" android:name="crc64a220455bad8a5d5e.MainActivity" />
    <activity android:label="logInActivity" android:noHistory="false" android:screenOrientation="portrait" android:theme="@style/SignInPage" android:name="crc6401374d2456a4365c.logInActivity" />
    <activity android:label="newMemberActivity" android:screenOrientation="portrait" android:theme="@style/newMember" android:name="crc6401374d2456a4365c.newMemberActivity" />
    <activity android:label="registerActivity" android:screenOrientation="portrait" android:theme="@style/AppTheme" android:name="crc6401374d2456a4365c.registerActivity" />
    <activity android:label="@string/app_name" android:noHistory="true" android:screenOrientation="portrait" android:theme="@style/MyTheme.Splash" android:name="crc6401374d2456a4365c.splashActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <service android:name="crc64a98abb514ffad9f1.KeepAliveService" />
    <receiver android:enabled="true" android:exported="false" android:label="Essentials Battery Broadcast Receiver" android:name="crc64a0e0a82d0db9a07d.BatteryBroadcastReceiver" />
    <receiver android:enabled="true" android:exported="false" android:label="Essentials Energy Saver Broadcast Receiver" android:name="crc64a0e0a82d0db9a07d.EnergySaverBroadcastReceiver" />
    <receiver android:enabled="true" android:exported="false" android:label="Essentials Connectivity Broadcast Receiver" android:name="crc64a0e0a82d0db9a07d.ConnectivityBroadcastReceiver" />
    <provider android:authorities="com.masslabs.semoto.fileProvider" android:exported="false" android:grantUriPermissions="true" android:name="xamarin.essentials.fileProvider">
      <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/xamarin_essentials_fileprovider_file_paths" />
    </provider>
    <provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="1999999999" android:authorities="com.masslabs.semoto.mono.MonoRuntimeProvider.__mono_init__" />
    <!--suppress ExportedReceiver-->
    <receiver android:name="mono.android.Seppuku">
      <intent-filter>
        <action android:name="mono.android.intent.action.SEPPUKU" />
        <category android:name="mono.android.intent.category.SEPPUKU.com.masslabs.semoto" />
      </intent-filter>
    </receiver>
    <provider android:authorities="com.masslabs.semoto.firebaseinitprovider" android:name="com.google.firebase.provider.FirebaseInitProvider" android:exported="false" android:initOrder="100" />
    <activity android:name="com.google.android.gms.common.api.GoogleApiActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:exported="false" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
  </application>
  <!-- Notice here that we have the package name of our application as a prefix on the permissions. -->
  <application android:label="@string/app_name">

    <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/mapKey" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    <!-- Necessary for apps that target Android 9.0 or higher -->
  </application>
</manifest>
xml android-fragments xamarin.android visual-studio-2019 supportmapfragment
1个回答
0
投票

尝试更改

<fragment 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      class="com.google.android.gms.maps.SupportMapFragment" />

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

以及在活动中使用:

 SupportMapFragment _mapFragment = SupportFragmentManager.FindFragmentById(Resource.Id.map).JavaCast<SupportMapFragment>(); // use JavaCast<> as a workaround.
 if (_mapFragment == null)
        {
            GoogleMapOptions mapOptions = new GoogleMapOptions()
                .InvokeRotateGesturesEnabled(true)
                .InvokeScrollGesturesEnabled(true)
                .InvokeCompassEnabled(true)
                .InvokeAmbientEnabled(true)
                .InvokeMapType(GoogleMap.MapTypeNormal)
                .InvokeZoomControlsEnabled(true)
                .InvokeCompassEnabled(true);

            _mapFragment = SupportMapFragment.NewInstance(mapOptions);
            _mapFragment.GetMapAsync(this);
        }

不要忘记在AndroidManifest.xml中添加以下内容>

<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="YOUR_API_KEY" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
© www.soinside.com 2019 - 2024. All rights reserved.