我的所有内容都与https://github.com/googlesamples/android-vision/tree/master/visionSamples/multi-tracker中的示例相同,但我的活动布局是这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/topLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:weightSum="100"
android:orientation="horizontal">
<be.citylife.communitypurchaseapp.view.camera.CameraSourcePreview
android:id="@+id/preview"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="60">
<be.citylife.communitypurchaseapp.view.camera.GraphicOverlay
android:id="@+id/overlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</be.citylife.communitypurchaseapp.view.camera.CameraSourcePreview>
<FrameLayout
android:id="@+id/sideContainer"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="40"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的平板电脑处于横向状态,我希望cameraPreviewSource始终保持高度并填满整个屏幕的高度,然后立即关闭它我有一个片段填充其余部分.
除了我的previewsource没有填满整个高度之外,这种布局是有效的.它上面有一个黑色横幅.甚至我的宽度实际上比我想要的小,你可以在屏幕截图上看到:
http://i61.tinypic.com/vctmw0.png
我在onLayout函数中使用CameraSourcePreview和宽度和高度,但它没有帮助.我在预览中知道它确实将屏幕填满了屏幕的底部,但在平板电脑上却没有.
任何人都知道如何解决这个问题?
编辑:
我认为这与此有关:
@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;
// Computes height and width for potentially doing fit width.
int childWidth = layoutWidth;
int childHeight = (int)(((float) layoutWidth / (float) width) * height);
// If height is too tall using fit width, does fit height instead.
if (childHeight > layoutHeight) {
childHeight = layoutHeight;
childWidth = (int)(((float) layoutHeight / (float) height) * width);
}
for (int i = 0; i < getChildCount(); ++i) {
getChildAt(i).layout(0, 0, childWidth, childHeight);
}
try {
startIfReady();
} catch (IOException e) {
Log.e(TAG, "Could not start camera source.", e);
}
}
Run Code Online (Sandbox Code Playgroud)
这是CameraSourcePreview的onlayout方法.
从CameraSourcePreview注释或删除下面的行,它应该没问题.我遇到了和你一样的问题,现在已经解决了.
if (childHeight > layoutHeight) {
childHeight = layoutHeight;
childWidth = (int)(((float) layoutHeight / (float) height) * width);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1070 次 |
| 最近记录: |