本文介绍了一个XML布局的背景设置为相机在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个项目,在那里我有一个XML布局,在它的按钮和所有这一切,我需要的背景是照相机,所以preVIEW是按钮后面,我怎么能做到这一点?

I have a project, where i have a xml layout, with buttons and all of that in it, and i need the background to be the camera, so the preview is behind the buttons, how can i do that?

推荐答案

下面是我的项目的xml:

Here is xml from my project:

<?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:

As said in documentation to CaptureActivity:

本活动开启相机并不会在后台实际的扫描
  线。它吸引取景器,以帮助用户正确地放置在酒吧code,
  示反馈作为图像处理正在发生,然后覆盖在
  结果当扫描是成功的。

ViewFinderView:

ViewFinderView:

此视图上,叠置相机preVIEW的顶部。它增加了取景器
  矩形和外面部分的透明度,以及激光扫描器
  动画和结果百分点。

如果你不想作出任何沙普斯只是没有使用ViewfinderView。

If you don't want to draw any sharpes just not use ViewfinderView.

看一看到CaptureActivity初始化相机的方法,也许这将是对你有所帮助。

Take a look to CaptureActivity init camera method, maybe it'll be helpful to you.

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在简历()方法创建:

SurfaceHadler is created in resume() method:

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

另外检查此

这篇关于一个XML布局的背景设置为相机在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 17:57