我想知道SurfaceView什么时候从布局中创建出来?
如果一个LiveCard是由Service创建的,并且没有Activity可以使用setContentView()设置这个布局,这种情况下会发生什么?
我还想知道程序中SurfaceView的创建需要哪些步骤。
以下是我的布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<SurfaceView
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
然后我有:
mLayout = (FrameLayout) inflater.inflate(R.layout.orientation_recorder, null);
mLayout.setWillNotDraw(false);
cameraView = (SurfaceView) mLayout.findViewById(R.id.camera_view);
cameraView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
Log.e("OR", "camera view sufrace destroyed");
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.e("OR", "camera view sufrace created");
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
Log.e("OR", "camera view sufrace changed "
+ " format: " + format
+ " width: " + width
+ " height: " + height);
}
});
但是,我无法创建SurfaceView,例如上面从未调用surfaceCreated()。
需要什么才能实现这一点?