java只获取相机的顶部
这几天以来我一直在讨论这个问题。我只想在屏幕上显示相机的一部分。这就是我想要的:
这就是我所做的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:orientation="vertical"
安卓:layout_width="match_parent"
安卓:layout_height="200dp">
<ScrollView
安卓:id="@+id/scrollView"
安卓:layout_width="match_parent"
安卓:layout_height="160dp"
安卓:scrollbars="none"
安卓:fillViewport="true"
>
<LinearLayout
安卓:id="@+id/linearLayoutBeautyContent"
安卓:layout_width="fill_parent"
安卓:layout_height="fill_parent"
安卓:orientation="vertical">
<SurfaceView
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:id="@+id/surfaceViewBeautyCamera"/>
</LinearLayout>
</ScrollView>
<TextView
安卓:id="@+id/scanText"
安卓:text="Scanning..."
安卓:layout_height="wrap_content"
安卓:layout_width="match_parent">
</TextView>
</LinearLayout>
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final LayoutInflater inflator = getLayoutInflater();
final LinearLayout inflate = (LinearLayout) inflator.inflate(R.layout.main, null);
final SurfaceView surfaceView = (SurfaceView) inflate.findViewById(R.id.surfaceViewBeautyCamera);
final SurfaceHolder holder = surfaceView.getHolder();
WindowManager mW = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
int screenWidth = mW.getDefaultDisplay().getWidth();
int screenHeight = mW.getDefaultDisplay().getHeight();
final ViewGroup.LayoutParams slayout = surfaceView.getLayoutParams();
slayout.width = screenWidth;
slayout.height = screenHeight;
surfaceView.requestLayout();
final ScrollView beautyContent = (ScrollView) inflate.findViewById(R.id.scrollView);
holder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
camera = getCamera();
camera.setPreviewDisplay(holder);
camera.setDisplayOrientation(90);
camera.startPreview();
} catch (IOException e) {
Log.i("Lucy", e.getMessage());
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
});
addContentView(inflate, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
}
public Camera getCamera() {
try {
final Camera open = Camera.open();
return open;
} catch (Exception ex) {
Log.i("Lucy", ex.getMessage());
return null;
}
}
当我这样做时,我得到:
其想法是将SurfaceView的大小设置为全屏,但减小滚动视图的大小。但我想要的是第一张照片。我做错了什么
意见:
当我完全向上滚动视图时。返回主屏幕并再次打开应用程序。我得到第一张图片。但是如果我再次滚动并返回main返回,我会得到第二个图像
还有其他策略吗
附言: 1.在相机顶部有其他视图也是一种选择,但我无法使用它,原因很长
# 1 楼答案
我不知道你为什么把
surfaceView
放在scrollView
中,但我忍受了你的布局文件和它对我的作用,正如你在预期的快照结果中所显示的那样编辑:
# 2 楼答案
试试这个布局。但我不明白为什么要使用scrollView
我张贴2版面
第一个曲面平均摄像机面为160dp的曲面
第二个问题是,相机将拍摄全屏大小的图片,但拍摄时只能看到160个窗口
# 3 楼答案
问题在于图元的高度设置: 根元素应该是相对布局,然后可以设置相机视图的固定高度,并将文本视图设置为与滚动视图下方的父元素和布局匹配的高度