【问题标题】:Android: CameraSourcePreview doesn't fill whole screen heightAndroid:CameraSourcePreview 没有填满整个屏幕高度
【发布时间】:2017-10-19 13:28:24
【问题描述】:

我正在使用compile 'com.google.android.gms:play-services-vision:9.4.0+'

用于二维码和 EAT-8、EAT-13 等。

但我无法管理大小

<com.testing.CameraSourcePreview
                android:id="@+id/preview"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <com.testing.GraphicOverlay
                    android:id="@+id/graphicOverlay"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />

            </com.testing.CameraSourcePreview>

【问题讨论】:

    标签: android google-play-services vision


    【解决方案1】:

    以上问题的解决方法是:

    从 CameraSourcePreview 中注释或删除以下行,应该没问题。我和你有同样的问题,现在已经解决了。

    if (childHeight > layoutHeight) {
    childHeight = layoutHeight;
    childWidth = (int)(((float) layoutHeight / (float) height) * width);
    

    }

    【讨论】:

      【解决方案2】:

      查看这个库...这也适用于 google play 服务。 你可以得到全屏扫描仪或任何你想要的尺寸。

      https://github.com/nisrulz/qreader

      【讨论】:

        【解决方案3】:
        private ViewGroup.LayoutParams paramsNotFullscreen; //if you're using RelativeLatout           
        
        @Override
        public void onConfigurationChanged(Configuration newConfig) 
        {
          super.onConfigurationChanged(newConfig);
        
        
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) //To fullscreen
        {
            paramsNotFullscreen=(ViewGroup.LayoutParams) CameraSourcePreview.getLayoutParams();
            RelativeLayout.LayoutParams params=new LayoutParams(paramsNotFullscreen);
            params.setMargins(0, 0, 0, 0);
            params.height=ViewGroup.LayoutParams.MATCH_PARENT;
            params.width=ViewGroup.LayoutParams.MATCH_PARENT;
            params.addRule(RelativeLayout.CENTER_IN_PARENT);
            CameraSourcePreview.setLayoutParams(params);
        
        } 
        else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) 
        {
            CameraSourcePreview.setLayoutParams(paramsNotFullscreen);
        }
        }
        

        【讨论】:

          【解决方案4】:
              @override
              protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
                 int width = 320;
                 int height = 240;
                 if (mCameraSource != null) {
                   Size size = mCameraSource.getPreviewSize();
                   if (size != null) {
                    width = size.getWidth();
                    height = size.getHeight();
                   }
                 }
          /* 
          Swap width and height sizes when in portrait, since it will be rotated 90 degrees 
          */
          
                  if (isPortraitMode()) {
                      int tmp = width;
                      width = height;
                      height = tmp;
                  }
          
                  final int layoutWidth = right - left;
                  final int layoutHeight = bottom - top;
          
                  for (int i = 0; i < getChildCount(); ++i) {
                      getChildAt(i).layout(0, 0, layoutWidth, layoutHeight);
                  }
          
                  try {
                      startIfReady();
                  } catch (IOException e) {
                      Log.e(TAG, "Could not start camera source.", e);
                  }
              }
          

          ******** 也不要忘记评论这一行:***


          mCameraSource = new CameraSource.Builder(context, myFaceDetector)
          // .setRequestedPreviewSize(640, 480). This line need to be commented or deleted
          .setFacing(CameraSource.CAMERA_FACING_FRONT)
          .setRequestedFps(15.0f)
          .build();
          

          这是正确的答案,它在纵向模式下工作,我没有 在横向模式下检查它,但它应该可以工作,因为我正在设置 布局宽度和高度根据屏幕尺寸。


          【讨论】:

            猜你喜欢
            • 2012-07-23
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-12-05
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多