关于布局

画中画效果

画中画效果代码实现

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <com.android.DualCamera.camera2.AutoFitTextureView
            android:id="@+id/texture_preview"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
        <com.android.DualCamera.camera2.AutoFitTextureView
            android:id="@+id/texture_preview2"
            android:layout_width="320dp"
            android:layout_height="240dp" />
    </LinearLayout>
</RelativeLayout>

并列效果

并列效果代码实现

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <com.android.DualCamera.camera2.AutoFitTextureView
            android:id="@+id/texture_preview"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1" />

        <com.android.DualCamera.camera2.AutoFitTextureView
            android:id="@+id/texture_preview2"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="fill_parent"/>
    </LinearLayout>
</RelativeLayout>

布局中使用 AutoFitTextureView 代替 TextureView。AutoFitTextureView 继承自 TextureView,能够根据传入的宽高值调整自身大小,目的是使预览画面不变形。AutoFitTextureView的代码实现在google android-Camera2Basic-master项目中,github上就可以下载。

参考的app 的demo:

camera2例子:
https://github.com/wangshengyang1996/Camera2Demo

使用camera2 api打开逻辑多摄来同时打开多个物理摄像头:
https://download.csdn.net/download/qq_32503365/12542520

Camera2 如何同时开启前后摄像头Preview并进行录像?
https://ask.csdn.net/questions/750899

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐