Android 使用TextureView的方形摄影机预览
我通过设置纹理矩阵将相机预览设置为平方,如下所示:Android 使用TextureView的方形摄影机预览,android,camera,textureview,Android,Camera,Textureview,我通过设置纹理矩阵将相机预览设置为平方,如下所示: <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
<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>
但单击actionbar的溢出按钮或底部的按钮时,会显示相机预览的隐藏部分,如下所示:
<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>
我不知道,有人能帮我吗?这是有时会发生的事情,我真的不知道为什么,但你可以很容易地阻止它。 在布局中,如果您有以下内容:
<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>
只需使用相同尺寸的framelayout或任何其他布局包装纹理视图,如下所示:
<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>
如果在运行时更改TextureView的尺寸,请记住将包装器FrameLayout的尺寸更改为完全相同