I'm trying to figure out how to put a compass on a map view in a xamarin android application. I wrote (copied from your github example) this code, and went as far as to create a compass.png file in the Drawables resource directory.
In the Activity:
_compass = FindViewById<Compass>(Resource.Id.compass);
_compass.GeoView = _mapFrag.MyMapView;
_compass.AutoHide = false;
and
In compass.axml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Esri.ArcGISRuntime.Toolkit.UI.Controls.Compass
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:id="@+id/compass" />
</RelativeLayout>
I'll be the first to admit that markup is not my forte. I've been scouring the Internet for documentation (I know, it's a dirty word). I've come up with a bunch of sites and documents that brag about a Compass control, and a github with compass code drowning in some larger (demonstration) project that I can't sort out.
The FindViewById returns null.
env:
VisualStudio 19 / Windoze 10 / Xamarin Android
Esri.ArcGISRuntime => v100.6.0
Esri.ArcGISRuntime.Toolkit => v100.4.0
Esri.ArcGISRuntime.Xamarin.Android => v100.6.0
(note: I tried at some point in the past to bring all the libraries up to date, and it broke something else in the project)
Any help working this out would be appreciated. Thanks.
First of all, I'd recommend you keep the versions in sync. If you target 100.6 of the runtime, make the toolkit also use v100.6. That guarantees the greatest compatibility.
Wrt to how to declare the compass, see the Compass sample in the repo:
axml:
code-behind:
(you can skip the Seekbar slider bit - the samples are really meant to be functional tests and the slider is there to test resizing works correctly)
So, I sync’d the libraries at 100.6.0. The code snippet I originally floated yesterday came from the two links that you supplied. Still, FindViewById returns null.
Right. Well, that's where I got the code snippets in the first place, so clearly there's something that I'm missing. When I run the code, FindViewById returns null.
If it's returning null, you probably have a resource generating issue in your code, or an issue with how you include the .axml in your project. The Xamarin forums are probably a better place to help trouble-shoot that.
I assume you set the content too like this?
arcgis-toolkit-dotnet/CompassMapViewSample.cs at master · Esri/arcgis-toolkit-dotnet · GitHub
and set the build action to AndroidResource as well as placing it under Resources\layout\
>>I assume you set the content too like this?
>>arcgis-toolkit-dotnet/CompassMapViewSample.cs at master · Esri/arcgis-toolkit-dotnet · GitHub(Resource.Id.compass);
if(_compass != null) {
_compass.GeoView = _mapFrag.MyMapView;
_compass.AutoHide = false;
}
The build action is AnrdoidResource, and the layout lives under Resources/Layout. To be honest, I didn’t know which would be a more appropriate forum. I am trying to extrapolate from your compass code example. Thanks.