使用Scenform将SceneView加载到一个片段后出现黑屏。

问题描述 投票:0回答:1

我正在做一个项目,它将在一个片段中拥有一个3D模型查看器。为了做到这一点,我决定使用sceneeform。在尝试在我的标签片段中显示SceneView后,我遇到了一个问题。

一切都按照例子和sceneform文档来做,但是...。sceneView 显示黑屏,无论我分配的是什么颜色。

这里是场景加载器

    @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>

android 3d augmented-reality sceneform
1个回答
1
投票

我通过添加暂停和恢复sceneview,以及片段来解决这个问题。

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

    @Override
    public void onResume() {
        super.onResume();
        try {
            sceneView.resume();
        } catch (CameraNotAvailableException e) {
            e.printStackTrace();
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.