Android Camera2 - 移除相机和底栏之间的黑色空间

时间:2016-08-31 14:57:57

标签: android android-camera2

我正在尝试开发一个使用Camera 2 API的应用程序,但是当我尝试编辑底栏的高度时遇到问题。我想删除相机和底栏之间的黑色空间。此外,我想延长相机的高度。

我关注了Google Camera2Basic示例。

enter image description here

我能解决这个问题吗?

感谢。

activity_camera.xml

<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
    android:background="#000"
    tools:context=".CameraActivity" />

fragment_camera2.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:foreground="?selectableItemBackground" >

    <widgets.AutoFitTextureView
        android:id="@+id/texture"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true" />

    <FrameLayout
        android:id="@+id/control"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:elevation="4dp"
        android:paddingBottom="12dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:paddingTop="12dp"
        android:background="@color/white" >

        <ImageButton
            android:id="@+id/picture"
            android:layout_width="@dimen/ic_camera"
            android:layout_height="@dimen/ic_camera"
            android:layout_gravity="center"
            android:background="@drawable/cam_circle_selector"
            android:contentDescription="@string/description_info"
            android:scaleType="fitXY"
            app:srcCompat="@drawable/ic_action_capture" />

    </FrameLayout>

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

You can add the Actionbar back which will cause your camera_view getting a little lower and remove the black divider. In styles.xml, replace this line

<style name="MaterialTheme" parent="android:Theme.Material.Light.NoActionBar.Fullscreen" />

with

<style name="MaterialTheme" parent="android:Theme.Material.Light" />

If you don't want to add Actionbar, you may have to modify AutoFitTextureView or Camera2BasicFragment class.