繁体   English   中英

Android Camera2Video预览问题

[英]Android Camera2Video Preview Issue

我正在使用Google's API Camera2VideoCamera2VideoFragmentAutoFitTextureView ,但有一个小问题。 当我使用preview在自定义FrameLayout ,这是不言而喻的left角落。

我找到了一种方法来预览预览以填充整个framelayout但是正如预期的那样,它看起来太拉伸了。 完美的解决方案是,如果拐角处可能有一些黑色边缘,并且屏幕位于中间。 我也不认为使充气机从中间膨胀布局会有所帮助,因为在某些情况下,屏幕足够大以至于预览无法正确放置,而放置在中间会损坏屏幕。

链接到Google's Camera2Video APIhttps//github.com/googlesamples/android-Camera2Video

我创建了一个简单的layout来展示我得到了什么。 (这是我在下载Google's API并删除了附带的按钮之后所做的唯一更改):

XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="#000"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:context="com.example.android.camera2basic.CameraActivity" />

</android.support.constraint.ConstraintLayout>

还有我所看到的图片。

在此处输入图片说明

您使用的示例将AutoFitTextureView 封装RelativeLayout的额外包装中。 在那里,它将纹理视图的位置定义

android:layout_alignParentStart="true" 
android:layout_alignParentTop="true"

导致您观察到的布局。

您的任务不需要此包装。 您可以将AutoFitTextureView直接嵌入CameraActivityFrameLayout中。 您的FrameLayout应该定义

android:gravity="center"

命令孩子们居中。

请注意,如果包装的ConstrantLayout唯一的孩子是id/container FrameLayout ,则可以删除它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM