不要调整/拉伸相机预览

时间:2015-11-07 14:14:59

标签: android android-studio android-camera preview

这是我的相机持有人:

            <SurfaceView
                android:id="@+id/cameraPreview"
                android:layout_width="match_parent"
                android:layout_height="300dp" />

我的问题是android延伸了相机预览,即使我设置了不起作用的PreviewSize! 请帮助!

2 个答案:

答案 0 :(得分:0)

与ImageView不同,SurfaceView没有内置程序来保持其宽高比。克服这种不足的可用方案分为将SurfaceView嵌入具有受控宽度和高度的容器中,以及在onMeasure()中设置SurfaceView的宽度和高度。

答案 1 :(得分:0)

[已解决] [工作] [:D]

我已经解决了这个问题:

<?xml version="1.0" encoding="utf-8"?>

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


<SurfaceView
    android:id="@+id/mySurfaceView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


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


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:orientation="vertical">

             //  put widgets here
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">


        <ImageView
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:src="@drawable/my_mask" /> //put a transparent image or         a mask for your SurfaceView


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white"
            android:orientation="vertical">

            //  put widgets here
        </RelativeLayout>
    </LinearLayout>

</LinearLayout>
</FrameLayout>

PS:不要忘记喜欢它是否适合你;)