gpt4 book ai didi

java - 在android中将xml布局的背景设置为相机

转载 作者:行者123 更新时间:2023-11-29 21:57:58 24 4
gpt4 key购买 nike

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

最佳答案

这是我项目中的 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 文档中所述:

This activity opens the camera and does the actual scanning on a background thread. It draws a viewfinder to help the user place the barcode correctly, shows feedback as the image processing is happening, and then overlays the results when a scan is successful.

取景器 View :

This view is overlaid on top of the camera preview. It adds the viewfinder rectangle and partial transparency outside it, as well as the laser scanner animation and result points.

如果你不想画任何锐化,就不要使用 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();

另外检查这个link

关于java - 在android中将xml布局的背景设置为相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12733079/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com