简体   繁体   English

使用TextureView平方相机预览

[英]Squared Camera Preview Using TextureView

i had made camera preview to squared by setting Texture Matrix, like this: 我已经通过设置“纹理矩阵”使摄像机预览变为正方形,如下所示:

在此处输入图片说明

but when click the overflow button of actionbar or the button in bottom, the hidden part of camera preview will be shown, like this: 但是当单击操作栏的溢出按钮或底部的按钮时,将显示摄像机预览的隐藏部分,如下所示:

在此处输入图片说明

I have no idea about this, could someone help me??? 我对此一无所知,有人可以帮我吗???

That is something that sometimes happens, I dont really know why, but you can easily prevent it. 有时会发生这种情况,我真的不知道为什么,但是您可以轻松地防止它发生。 In you layout, if you have something like: 在布局中,如果您有类似以下内容:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@color/black" >


        <TextureView
            android:id="@+id/textureView"
            android:layout_width="YOUR_WIDTH"
            android:layout_height="YOUR_HEIGHT" >
        </TextureView>

        <!-- other stuff -->
  </LinearLayout>

Just wrap the texture view with a framelayout, or any other layout, with the same dimensions, something like this: 只需用相同的尺寸用框架布局或任何其他布局包装纹理视图,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@color/black" >

    <FrameLayout
            android:layout_width="YOUR_WIDTH"
            android:layout_height="YOUR_HEIGHT" 
       android:background="@color/black" >


        <TextureView
            android:id="@+id/textureView"
            android:layout_width="YOUR_WIDTH"
            android:layout_height="YOUR_HEIGHT" >
        </TextureView>
    </FrameLayout>

        <!-- other stuff -->
  </LinearLayout>

If you change the dimensions of the TextureView in runtime, remember also to change the dimensions of the wrapper FrameLayout to exactly the same 如果在运行时更改TextureView的尺寸,请记住还要将包装器FrameLayout的尺寸更改为完全相同

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

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