安卓 : display foreground (and views) in a camera preview in order to make an old camera back look

标签 android android-layout camera surfaceview

我在使用相机预览时遇到了一些问题(在 FrameLayout 中)。 我想实现这样的目标:

https://lh4.ggpht.com/aFPHmlYNaSAAJV2er2inD9dlXS61Sj-V1qyYeCpfgMCPY18kgdQEdIOyWkaXOlWeAkM=h900-rw或者这个:https://lh4.ggpht.com/_OkN-O2mb3s4VO6QoSj15cTdzTBic_Ji8-ZGg16PmvfFUNWpQHfaZuN6ofwPWOHhr34=h900-rw

但到目前为止,我所能做的就是: - 在 FrameLayout 中进行全屏预览 - 一个微小的预览错位(我希望它水平居中并在顶部 40 dp 处)

到目前为止,这是我的布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/background_app_photo_transparent" tools:context="jmf.net.testsapp.CameraActivity" > <FrameLayout android:layout_width="320dp" android:layout_height="240dp" android:layout_gravity="center_horizontal" android:layout_marginTop="40dp" android:id="@+id/master_layout" /> </FrameLayout>

第一个 FrameLayout 是我放置九个可绘制补丁的地方,它必须恢复一些相机预览。 第二个 FrameLayout (id/master_layout) 是我创建 SurfaceView 以显示相机预览的那个。

但是当我尝试这个时,我在左下角看到了相机预览。

所以我想我的开始很糟糕。

这是我的问题:如何管理布局和相机预览才能获得如下图所示的内容?

最佳答案

好的,我找到了一个方法。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
android:columnCount="3"
android:rowCount="3">


<ImageView
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:id="@+id/imageView2"
    android:background="@drawable/slice_0_0"
    android:layout_gravity="fill"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_above="@+id/imageView5"
    android:layout_toLeftOf="@+id/imageView3"
    android:layout_toStartOf="@+id/imageView3" />

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:id="@+id/imageView3"
    android:background="@drawable/slice_0_1"
    android:layout_gravity="fill"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/imageView6"
    android:layout_toRightOf="@+id/imageView5"
    android:layout_toEndOf="@+id/imageView5" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:id="@+id/imageView4"
    android:background="@drawable/slice_0_2"
    android:layout_gravity="fill"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_above="@+id/imageView6"
    android:layout_toRightOf="@+id/imageView3"
    android:layout_toEndOf="@+id/imageView3" />


<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/imageView5"
    android:background="@drawable/slice_1_0"
    android:layout_gravity="fill"
    android:layout_below="@+id/imageView3"
    android:layout_toLeftOf="@+id/master_layout"
    android:layout_toStartOf="@+id/master_layout"
    android:layout_alignBottom="@+id/master_layout" />

<FrameLayout
    android:layout_width="320dp"
    android:layout_height="240dp"
    android:layout_gravity="center_horizontal"
    android:id="@+id/master_layout"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="40dp"
    />

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/imageView6"
    android:background="@drawable/slice_1_2"
    android:layout_gravity="fill"
    android:layout_toRightOf="@+id/master_layout"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/imageView3"
    android:layout_alignBottom="@+id/master_layout" />


<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView7"
    android:background="@drawable/slice_2_0"
    android:layout_gravity="fill"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignBottom="@+id/imageView9"
    android:layout_toLeftOf="@+id/imageView3"
    android:layout_toStartOf="@+id/imageView3"
    android:layout_below="@+id/imageView5" />

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/imageView8"
    android:background="@drawable/slice_2_1"
    android:layout_gravity="fill"
    android:layout_toLeftOf="@+id/imageView6"
    android:layout_below="@+id/master_layout"
    android:layout_toRightOf="@+id/imageView5"
    android:layout_toEndOf="@+id/imageView5" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView9"
    android:background="@drawable/slice_2_2"
    android:layout_gravity="fill"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/imageView6"
    android:layout_alignLeft="@+id/imageView6"
    android:layout_alignStart="@+id/imageView6" />

</RelativeLayout>

抱歉打扰了。

关于安卓 : display foreground (and views) in a camera preview in order to make an old camera back look,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29397651/

相关文章:

android - 开发 android 客户端应用程序以使用 BigBlueButton 服务器

android - Google+ Auth 容错(代码已兑换)

android - 如何在 Android 上播放原生相机声音

iphone - 从 UIImagePicker 中删除相机控件 - 如何放大到全屏 - iPhone/iPad

angularjs - 如何修复flutter webview中无法访问视频流(NotAllowedError)以使用html5+webRTC相机api?

android - 设备在Android中连接到WiFi时如何获取蜂窝网络的IP地址

android - 在 Android studio 中更改 cmake 目录

java - 由于将 minSdkVersion 从 21 更改为 14 导致错误

android - 自定义样式列表分隔符

Android v7 工具栏标题文本字体