【发布时间】:2015-12-16 20:55:50
【问题描述】:
我正在尝试创建一个简单的 android 原生视图。一旦我得到了整件事。与渲染器一起工作 - 它将被实现为摄像机视图。
我的渲染器:
[assembly: ExportRenderer(typeof(CameraPage), typeof(CameraPageRenderer))]
namespace CameraTester2.Droid
{
public class CameraPageRenderer : PageRenderer, TextureView.ISurfaceTextureListener
{
Activity activity;
global::Android.Views.View view;
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
activity = this.Context as Activity;
view =activity.LayoutInflater.Inflate(Resource.Layout.TestLayout, this, true);
AddView(view);
}
但是.. 当我添加视图时 - 我得到了一个 stackoverflow 执行,我就是不知道为什么我做错了。
我尝试过以下示例: https://blog.xamarin.com/customize-your-xamarin-forms-app-with-pages-for-each-platform/
http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/contentpage/
Android 中的页面是一个带有标签的简单页面 - 不要认为您需要查看它。 共享 PCL 项目中的页面只是一个空的 Xamarin.Forms Xaml 页面。
有什么建议吗?
我还想知道如何创建自己的活动 - 并将其设置为上下文。如果我尝试像这样设置上下文:
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
activity = this.Context as CameraActivity;
view =activity.LayoutInflater.Inflate(Resource.Layout.TestLayout, this, true);
AddView(view);
}
Activity 被设置为 null。提前感谢您的任何建议。
【问题讨论】:
-
堆栈跟踪在哪里?没有它,很难猜出它溢出了什么。这是具有相机页面渲染器的 Xamarin 传播者项目:github.com/pierceboggan/Moments
标签: android android-activity xamarin renderer