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

CaptureActivityのドキュメントで述べられているように:

このアクティビティはカメラを開き、バックグラウンドスレッドで実際のスキャンを実行します。ビューファインダーを描画して、ユーザーがバーコードを正しく配置できるようにし、画像処理が行われているときにフィードバックを表示し、スキャンが成功すると結果をオーバーレイします。

ViewFinderView:

このビューは、カメラプレビューの上にオーバーレイされます。ビューファインダーの長方形とその外側の部分的な透明度、およびレーザースキャナーのアニメーションと結果ポイントを追加します。

シャープを描画したくない場合は、ViewfinderViewを使用しないでください。

CaptureActivityinitcameraメソッドを見てください。おそらくそれはあなたに役立つでしょう。

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 に答える