2017-07-27 39 views
1

使用以下代碼在佈局中顯示攝像機視圖。Javacameraview全寬作爲邊界佈局的寬度

<?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的。它佔據了高度,但是框架的寬度沒有被完全佔用,因此在寬度旁邊有黑色背景。我怎樣才能解決這個問題?

回答

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> 
+0

我想讓相機只佔用屏幕的一部分 –

+0

您可以使用保證金。 –

+0

保證金?......... –