简体   繁体   中英

Android Camera2 - Remove black space between camera and bottom bar

I'm trying to develop an application that uses Camera 2 API, but I have a problem when I try to edit the height of the bottom bar. I would like to remove the black space between the camera and bottom bar. Moreover, I would like to extend the camera height.

I followed the Google Camera2Basic example.

在此输入图像描述

Could I fix this problem?

Thanks.

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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