I'm trying to add a UrohSharp Surface to a LinearLayout
in a class inheriting from ViewGroup
(to place in in the left hand corner of another view).
Most examples showing UrhoSharp implemented in Android is done directly in the main activity like this:
protected override async void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var mLayout = new AbsoluteLayout(this);
surface = UrhoSurface.CreateSurface(this);// (this, , true);
mLayout.AddView(surface);
SetContentView(mLayout);
dronModel = await surface.Show<DroneScene>(new ApplicationOptions("Data"));
}
Or with a element in the layout file:
<Urho.Droid.UrhoSurfacePlaceholder
android:id="@+id/DroidModelId"
android:background="@color/colorPrimary"
android:layout_height="300dp"
android:layout_width="match_parent"/>
And replace it like so:
public override async void OnViewCreated(Android.Views.View view, Bundle savedInstanceState)
{
base.OnViewCreated(view, savedInstanceState);
surface = UrhoSurface.CreateSurface(base.Activity);
UrhoSurfacePlaceholder parent = view.FindViewById<UrhoSurfacePlaceholder>(Resource.Id.DroidModelId);
parent.AddView(surface);
droneModel = await surface.Show<DroneModel>(new ApplicationOptions("Data"));
But, what I need to do is create a view of some sort to incapsle the Urho code and reference it somehow like this:
<My.App.Droid.Views.Drone.Model.DroneModelView
android:id="@+id/DroneModel2"
android:layout_marginTop="32dp"
android:layout_marginLeft="32dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="55dp"
android:layout_height="55dp"
android:background="@null"/>
And then grab it from the main activity view:
droneModelView = FindViewById<DroneModelView>(Resource.Id.DroneModel2);
Since UrhoSurface.CreateSurface
needs the Activity object I'm not sure how to best approch this - as far as I know there is no "clean" way to reach the activity from a class inherithing ViewGroup
? The end goal is to show the 3D model in a view containing lots of other elements that are referenced in a similar fashion.
here is a simple example which add RatingBar to LinearLayout in CustomView,you could refer to it,change the RatingBar to your UrohSharp Surface