使用 Scenform 将 SceneView 加载到片段中后黑屏 [英] Black screen after loading SceneView, using Scenform, into a fragment

查看:27
本文介绍了使用 Scenform 将 SceneView 加载到片段中后黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展一个项目,该项目将在一个片段中包含一个 3D 模型查看器.为了做到这一点,我决定使用场景形式.我在我的选项卡片段中尝试显示 SceneView 后遇到了问题.

I am working on a project that will have a 3D model viewer in one fragment. In order to do so, I decided to use sceneform. I have encountered a problem with SceneView, after trying to display it, in my tab fragment.

一切都是根据示例和场景形式文档完成的,但是 sceneView 显示黑屏,无论我指定的颜色如何.

Everything is done according to examples and sceneform documentation, but sceneView display black screen, regardless of the colour I am assigning.

这里是场景加载器

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        vw = inflater.inflate(R.layout.fragment_open_gl, container, false);
        sceneView = vw.findViewById(R.id.scene_view);
        return vw;
    }

和片段:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".OpenGL">

    <com.google.ar.sceneform.SceneView
        android:id="@+id/scene_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/Crimson"/>

</FrameLayout>

推荐答案

我通过添加暂停和恢复场景视图以及片段解决了这个问题:

I solved the issue by adding pausing and resuming sceneview, along with the fragment:

    @Override
    public void onPause() {
        super.onPause();
        sceneView.pause();
    }

    @Override
    public void onResume() {
        super.onResume();
        try {
            sceneView.resume();
        } catch (CameraNotAvailableException e) {
            e.printStackTrace();
        }
    }

这篇关于使用 Scenform 将 SceneView 加载到片段中后黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆