简介
我在我的应用程序中实现了一个摄像头,它采用4:3比例的图像,这是我的XML相机
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageCapture">
</FrameLayout>
在我的相机课程中,我然后在这个对象上调用我的表面视图:
public FrameLayout preview;
//,,,
preview = (FrameLayout) rootView.findViewById(R.id.imageCapture);
//...
myCameraSurfaceView = new Surface(getActivity(), myCamera);
preview.addView(myCameraSurfaceView);
一切都很好,但是!
问题
我的相机拍摄4:3照片,如下所示:
p.setPictureSize(bWidthFourThree, bHeightFourThree);
myCamera.setParameters(param);
所以我拍摄的图像是我想要的4:3照片。 但是我的相机预览(framelayout / surfaceview实现)包裹整个屏幕。
我想要什么
现在我知道问题是什么,它包裹了屏幕,因为宽度和高度都与帧布局的父级相匹配。我想要的是:
任何帮助都非常感谢,如果需要任何额外的信息,请告诉我,我会更新这篇文章
答案 0 :(得分:0)
在获得摄像机的变量值之前,您不需要创建FrameLayout。让我们说FrameLayout进入了一个LinearLayout。您将实例化然后设置它的参数,所以:
//I used getContext(), but you can change it to yours
FrameLayout frameLayout = new FrameLayout(getContext());
//The layout parameters must ALWAYS be related to the parent. So, if it's a LinearLayout, you'll use LinearLayout.LayoutParams
//Create the parameters using the dimensions you want
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(bWidthFourThree, bHeightFourThree);
//Add your FrameLayout to the LinearLayout passing the parameters
yourLinearLayout.addView(frameLayout, layoutParams);
这样,您将实例化一个FrameLayout,并在您拥有它们之后将相机尺寸传递给它。之后,您可以通过添加视图(正如您所做的那样)将图像传递给FrameLayout。
让我知道它是否对您有所帮助,如果是,请记住upvote /选择正确答案。如果您有更多问题,请回复此答案,欢呼