无法画上一个自定义的SurfaceView类之上自定义、画上、SurfaceView

由网友(醉生梦死)分享简介:我已经使用了例如指南创建一类被称为相机preVIEW它继承自SurfaceView类,并显示相机preVIEW。我也创造了另一个叫DrawOnTop自定义视图类,它只是直接继承视图,我用这个上的preVIEW顶部绘制文本和其他项目。每个视图级工作正常,对自己,但是当我打开这两种观点到活动中,摄像头preVIEW始终占主...

我已经使用了例如指南创建一类被称为相机preVIEW它继承自SurfaceView类,并显示相机preVIEW。我也创造了另一个叫DrawOnTop自定义视图类,它只是直接继承视图,我用这个上的preVIEW顶部绘制文本和其他项目。每个视图级工作正常,对自己,但是当我打开这两种观点到活动中,摄像头preVIEW始终占主导地位,没有对象或文本从DrawOnTop类出现在相机preVIEW之上。

I've used the example guide to create a class called CameraPreview which inherits from the SurfaceView class, and which displays the camera preview. I've also created another custom view class called DrawOnTop which just inherits directly from View, and I use this for drawing text and other items on top of the preview. Each view class works fine on its own, but when I load both views into the activity, the CameraPreview always dominates and none of the objects or text from the DrawOnTop class appear on top of the camera preview.

由于我使用了两个自定义视图类,我没有打扰夸大任何视图类从XML在活动的onCreate,所以的onCreate不包含任何调用的setContentView(...)。相反,我每个实例化视图类,并加载每个视图对象为使用addContentView(...),活动的根视图即

Because I'm using two custom view classes, I'm not bothering to inflate any view classes from XML in the activity's onCreate, so the onCreate doesn't contain any call to setContentView(...). Instead, I instantiate each view class, and load each view object into the activity's root view using addContentView(...), i.e.

CameraPreview preview = new CameraPreview(this); 
addContentView(preview, new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));

DrawOnTop drawontop = new DrawOnTop(this);       
addContentView(drawontop, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
drawontop.setVisibility(View.VISIBLE);
drawontop.bringToFront();

我看了一下活动的根本观点,它原来是类型的FrameLayout的。正如我前面所说,这种方法工作正常的自己每个视图。

I had a look at the activity's root view, and it turns out to be of type FrameLayout. As I said above, this methodology works fine for each view on its own.

要获得出现在相机preVIEW顶部DrawOnTop类的,我用bringToFront尝试(),但它并没有任何影响。我测试上三星Galaxy Note 2 LTE运行Android 4.1.1版本的应用程序。

To get the DrawOnTop class to appear on top of the camera preview, I've tried using bringToFront() but it doesn't have any effect. I'm testing the app on a Samsung Galaxy Note 2 LTE running Android Version 4.1.1.

谁能告诉我什么,我做错了什么?

Can anyone tell me what I'm doing wrong?

推荐答案

这个链接可以帮助:How绘制覆盖在Android上使用相机SurfaceView?

您只需把你的相机preVIEW视图成的FrameLayout,和你的DrawOnTop观点在同一水平的FrameLayout,即

You just need to put your CameraPreview view into a FrameLayout, and have your DrawOnTop view at the same level as the FrameLayout, i.e.

FrameLayout frame = new FrameLayout(this);
addContentView(frame, new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
CameraPreview preview = new CameraPreview(this); 
frame.addView(mPreview);

DrawOnTop drawontop = new DrawOnTop(this);       
addContentView(drawontop, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
drawontop.setVisibility(View.VISIBLE);
drawontop.bringToFront();

这是否为你工作?

Does that work for you?

阅读全文

相关推荐

最新文章