PageRenderer不适用于camera2 API

时间:2019-03-20 01:24:40

标签: xamarin xamarin.forms xamarin.android android-camera

我正试图通过页面渲染使Xamarin Forms中的Camera2 API正常工作。

[assembly: ExportRenderer(typeof(CameraPage), typeof(CameraActivity))]
namespace BlueDemo.Droid
{
     [Activity(Label = "CameraActivity")]
     public class CameraActivity : PageRenderer
{
        Activity activity;
        TextureView textureView;
        global::Android.Views.View view;

    public CameraActivity(Context context) : base(context)
    {
    }

    protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
    {
        base.OnElementChanged(e);

        if (e.OldElement != null || Element == null)
        {
            return;
        }

        try
        {
            SetupUserInterface();
            AddView(view);


        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(@"           ERROR: ", ex.Message);
        }
    }
    void SetupUserInterface()
    {
        //activity = Context as Activity;
        view = activity.LayoutInflater.Inflate(Resource.Layout.activity_camera, this, false);
        activity.FragmentManager.BeginTransaction().Replace(Resource.Id.container, Camera2BasicFragment.NewInstance()).Commit();

    }

断点确实击中了LayoutInflater,但没有打开摄像机的视图。原始的Camera2 API:Camera2 API link for camera activity

这具有SetContentView,它不适用于Page Renderer。

0 个答案:

没有答案