Camera2预览不会全屏显示

时间:2015-12-31 10:47:27

标签: android android-camera surfaceview android-camera2

我正在解决一个问题,让相机2在一个表面视图上全屏显示。它确实填满了表面视图的整个高度,但是当涉及宽度时我遇到了问题(请参见下面的图片)。

我的布局文件如下所示:

<android.view.SurfaceView
    android:id="@+id/preview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentBottom="true">
</android.view.SurfaceView>

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress"
    android:ems="10"
    android:id="@+id/username"
    android:hint="Brukernavn"
    android:gravity="center"
    android:layout_above="@+id/password"
    android:layout_centerHorizontal="true" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:ems="10"
    android:hint="Passord"
    android:id="@+id/password"
    android:gravity="center"
    android:layout_centerVertical="true"
    android:layout_alignLeft="@+id/username"
    android:layout_alignStart="@+id/username" />

在surfaceCreated方法中,我运行以下代码以设置Surfaceview的所需大小

Size[] size = strem_conf.getOutputSizes(SurfaceHolder.class); 
 ((SurfaceView)findViewById(R.id.preview)).getHolder().setFixedSize(size[0].
getWidth(),size[0].getHeight());

enter image description here

感谢您提供任何帮助或指导!

编辑:它似乎在横向模式下运行良好,因此问题似乎在纵向模式下出现。

1 个答案:

答案 0 :(得分:0)

我有类似的问题。我使用与默认主题不同的主题来修复我的应用程序。 在AndroidManifest.xml上我添加了:

    android:theme="@style/MaterialTheme">`

和styles.xml:

<resources>
<style name="MaterialTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowFullscreen">true</item>
</style>