我使用以下代码在布局中显示相机视图。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:orientation="vertical"
android:weightSum="2">
<RelativeLayout
android:id="@+id/cam_frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary">
</LinearLayout>
<org.opencv.android.JavaCameraView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:id="@+id/AddPersonPreview"
opencv:show_fps="false"
opencv:camera_id="any" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@color/colorPrimary"
android:layout_weight="0">
</LinearLayout>
</LinearLayout>
我试图让摄像机视图占据cam_frame
的全宽和全高。它占据了高度但框架的宽度没有被完全占据,因此在宽度旁边有黑色背景。我怎样才能解决这个问题?
答案 0 :(得分:1)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/cam_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary">
</LinearLayout>
<org.opencv.android.JavaCameraView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:layout_margin="30dp"
android:id="@+id/AddPersonPreview"
opencv:show_fps="false"
opencv:camera_id="any" />
</RelativeLayout>
</LinearLayout>