首页 > 解决方案 > 如何在片段而不是活动中使用 OpenGl 绘制形状

问题描述

我正在使用此说明:https ://developer.android.com/training/graphics/opengl/environment 。

但我必须使用片段而不是活动。另外我在主要片段上有一些图片,并且使用 OpenGL 我必须绘制一些形状。但是,当我启动应用程序时,它变成了空的黑屏。在某个地方我发现我可以为片段编写类似的东西,但是如果我删除这行代码,我的 xml 布局就会在应用程序上,但我需要混合片段并在这个片段上绘制形状。

override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        lifecycle.addObserver(viewModel)
        val rootView = inflater.inflate(R.layout.main_fragment, container, false)

        val fL = rootView.findViewById<ConstraintLayout>(R.id.main)
        customGLSurfaceView = CustomGLSurfaceView(requireContext())
        fL.addView(customGLSurfaceView) // this line
        return rootView
    }

标签: androidkotlinandroid-fragmentsopengl-es

解决方案


推荐阅读