在相机视图顶部使用多个setContentView自定义Android应用程序UI



我是一名Android开发人员,正在开发原型应用程序。我在我的应用程序中使用了一个专有的条形码扫描仪,当我的条形码扫描仪运行时,我想在屏幕底部覆盖一个小菜单。理想情况下,此菜单的大小约为屏幕的五分之一,并包含几个按钮。我曾想过使用片段来实现这个UI,但我很难将扫描仪的SDK教程转换为使用片段。

现在,我的活动生成了一个全屏摄像机视图,条形码选择器覆盖在中间,代码如下:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);

ScanditSDKAutoAdjustingBarcodePicker picker = new
ScanditSDKAutoAdjustingBarcodePicker(
    this, sScanditSdkAppKey,ScanditSDKAutoAdjustingBarcodePicker.CAMERA_FACING_BACK);
setContentView(picker);
mBarcodePicker = picker;

如何使用此设置覆盖可以在XML文件中描述的菜单?通过另一个setContentView()调用XML布局会覆盖整个屏幕,即使我将其背景设置为透明(或null)也是如此。

如果这个问题措辞不当,请提前道歉。

我已经检查了此ScanditSDKAutoadjust BarcodePicker的文档,并找到了下一个链接:http://docs.scandit.com/stable/android/android-scanview-options.html

由于BarcodePicker是一个普通的RelativeLayout,您可以像其他视图一样将其添加到自己的布局中:

// Set app key. This will only have to be done once
ScanditLicense.setAppKey("yourAppKey");
// Create the scan view. Note that you will have to configure the settings in your app 
// since the default settings have all symbologies disabled and you won't be able to 
// scan anything.
BarcodePicker barcodePicker = new BarcodePicker(context, ScanSettings.create());
// Add the scan view to the root view.
rootView.addView(barcodePicker);

因此,您可以使用XML定义的具有布局的"普通"活动。您可以使用RelativeLayout。在那里,您可以放置用于选取器和菜单的容器(FrameLayout),并与RelativeLayout的底部对齐。您可以通过id找到容器,并使用addView()将picker放入该容器中。

最新更新