Android:CameraSourcePreview无法填满整个屏幕高度

时间:2017-05-19 12:05:47

标签: android google-play-services vision

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

用于QR码和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>

4 个答案:

答案 0 :(得分:4)

上述问题的解决方案是:

评论或删除CameraSourcePreview下面的行,它应该没问题。我遇到了和你一样的问题,现在已经解决了。

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

}

答案 1 :(得分:0)

查看此库...这也适用于Google Play服务。 你可以获得全屏扫描仪或任何你想要的尺寸。

https://github.com/nisrulz/qreader

答案 2 :(得分:0)

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);
}
}

答案 3 :(得分:0)

    @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();

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