Android:CameraSourcePreview不会填满整个屏幕高度



我正在使用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>

上述问题的解决方案是:

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

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

}

看看这个库...这也是谷歌播放服务的工作。 您可以获得全屏扫描仪或您想要的任何尺寸。

https://github.com/nisrulz/qreader

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

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


最新更新