1

我有一个项目,我有一个xml布局,里面有按钮和所有这些,我需要背景是camera,所以预览在后面buttons,我该怎么做?

4

1 回答 1

2

这是我项目中的 xml:

<?xml version="1.0" encoding="UTF-8"?>
<!--
     Copyright (C) 2008 ZXing authors Licensed under the Apache License, 
    Version 2.0 (the "License"); you may not use this file except in compliance 
    with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
    Unless required by applicable law or agreed to in writing, software distributed 
    under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 
    OR CONDITIONS OF ANY KIND, either express or implied. See the License for 
    the specific language governing permissions and limitations under the License.


-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FF8090A0" >

    <SurfaceView
        android:id="@+id/preview_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <com.x09soft.scanner.zxing.ViewfinderView
        android:id="@+id/viewfinder_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/transparent" />

    <ImageButton
        android:id="@+id/btn_flash"
        android:background="@drawable/flash_off"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_gravity="right|center_vertical"/>

</FrameLayout>

CaptureActivity 和 ViewfinderView 您可能会看到(如上所述)here

正如 CaptureActivity 的文档中所说:

此活动打开相机并在后台线程上进行实际扫描。它绘制一个取景器来帮助用户正确放置条形码,在图像处理过程中显示反馈,然后在扫描成功时覆盖结果。

取景器视图:

此视图覆盖在相机预览之上。它在其外部添加了取景器矩形和部分透明度,以及激光扫描仪动画和结果点。

如果您不想绘制任何锐器,请不要使用 ViewfinderView。

看看 CaptureActivity init camera 方法,也许对你有帮助。

private void initCamera(SurfaceHolder surfaceHolder) {
        try {
            cameraManager.openDriver(surfaceHolder);
            // Creating the handler starts the preview, which can also throw a
            // RuntimeException.
            if (handler == null) {
                handler = new CaptureActivityHandler(this, decodeFormats,
                        characterSet, cameraManager);
            }
        } catch (IOException ioe) {
            Log.w(TAG, ioe);
            displayFrameworkBugMessageAndExit();
        } catch (RuntimeException e) {
            // Barcode Scanner has seen crashes in the wild of this variety:
            // java.?lang.?RuntimeException: Fail to connect to camera service
            Log.w(TAG, "Unexpected error initializing camera", e);
            displayFrameworkBugMessageAndExit();
        }
    }

SurfaceHadler 在 resume() 方法中创建:

 SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();

另外检查这个链接

于 2012-10-04T18:30:52.737 回答