谁知道如何在Rajawali Surface View顶部添加用户界面? 我查看了rajawali文档,但无法正常工作
答案 0 :(得分:0)
以下方法对我有用:创建要添加到布局中的UI元素,我使用ConstraintLayout
作为容器。不要通过xml创建SurfaceView
,而是通过编程方式创建。以使其与所有其他UI元素重叠并使用所有可用空间的方式创建它。这样,即使在技术上应该将UI元素隐藏在前面的SurfaceView
中。
下面是我的代码,如何设置SurfaceView
。请注意,constraintLayout是容器布局的名称,其中还包含其他按钮。
surfaceView = new SurfaceView(getContext());
surfaceView.setFrameRate(30.0);
surfaceView.setRenderMode(ISurface.RENDERMODE_WHEN_DIRTY);
surfaceView.setSurfaceRenderer(YOUR_RENDERER);
surfaceView.setLayoutParams(new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_CONSTRAINT, ConstraintLayout.LayoutParams.MATCH_CONSTRAINT));
surfaceView.setId(View.generateViewId());
constraintLayout.addView(surfaceView, 0);
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(constraintLayout);
constraintSet.connect(surfaceView.getId(), ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT);
constraintSet.connect(surfaceView.getId(), ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT);
constraintSet.connect(surfaceView.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM);
constraintSet.connect(surfaceView.getId(), ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP);
constraintSet.applyTo(constraintLayout);