android - 如何在 ViewGroup 类中将 UrhoSharp Surface 附加到 LinearLayout
问题描述
我正在尝试将 UrohSharp Surface 添加到LinearLayout
继承自的类中ViewGroup
(放置在另一个视图的左下角)。
大多数显示在 Android 中实现 UrhoSharp 的示例都是直接在主要活动中完成的,如下所示:
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"));
}
或者使用布局文件中的元素:
<Urho.Droid.UrhoSurfacePlaceholder
android:id="@+id/DroidModelId"
android:background="@color/colorPrimary"
android:layout_height="300dp"
android:layout_width="match_parent"/>
并像这样替换它:
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"));
但是,我需要做的是创建某种视图来封装 Urho 代码并以如下方式引用它:
<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"/>
然后从主活动视图中抓取它:
droneModelView = FindViewById<DroneModelView>(Resource.Id.DroneModel2);
由于UrhoSurface.CreateSurface
需要 Activity 对象,我不确定如何最好地解决这个问题 - 据我所知,没有“干净”的方法可以从类继承中访问活动ViewGroup
?最终目标是在包含许多以类似方式引用的其他元素的视图中显示 3D 模型。
解决方案
这是一个简单的例子,它在 CustomView 中将 RatingBar 添加到 LinearLayout,您可以参考它,将 RatingBar 更改为您的 UrohSharp Surface
推荐阅读
- python - 将相似的索引值分组并通过新索引 pandas 重新索引每个组
- asp.net-mvc - Asp.net Mvc 和 Boostrap 4 分页 - 显示活动的当前页面
- c# - 'public / static' 修饰符对此项无效
- java - 解析来自 REST 的压缩 InputStream
- ubuntu - 在 WSL 中完全删除 anaconda
- c++ - 我尝试编写蛇游戏,游戏运行良好。我只有一个错误,无法找出原因
- rabbitmq - 何时使用 REST API,何时使用消息服务(例如 RabbitMQ)在微服务之间交换数据?
- regex - 正则表达式将找到的字符限制为 2 个或 3 个不超过
- javascript - 在 http.post 中使用 Promise.reject() 进行错误处理
- spss - 比较组内各行之间的值