我有以下布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.test.MainActivity" >
<org.opencv.android.JavaCameraView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:id="@+id/MainActivityCameraView"
opencv:show_fps="true"
opencv:camera_id="any" />
<com.example.draw.DrawTransparency
android:id="@+id/view"
android:layout_width="200dp"
android:layout_height="200dp"
/>
JavaCameraView是简单的相机预览。 DrawTransparency类:
public class DrawTransparency extends View {
....
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// draw something
}
}
在MainActivity中:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mOpenCvCameraView = (JavaCameraView) mOpenCvCameraView = (JavaCameraView) findViewById(R.id.MainActivityCameraView);
mOpenCvCameraView.setCvCameraViewListener(this);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
}
我的问题是:为什么我看到DrawTransparency绘制的图像,虽然我没有在onCreate()方法中调用DrawTransparency?我想在屏幕上绘制一些东西(DrawTransparency类),但只有在满足某些条件后...
答案 0 :(得分:0)
我对android / java有一个小知识,因为我刚刚开始使用它。 但是从我看到的DrawTransparency是你在onCreate中设置的activity_main.xml的一部分,所以它的onDraw()将被执行。