Android 何时从布局(以编程方式)创建SurfaceView?
我想知道什么时候从布局中创建SurfaceView 这是一种从Google Glass上的LiveCard服务创建布局的场景,因此没有可以使用setContentView()设置此布局的活动 不过,我想知道怎样才能以编程方式创建SurfaceView 我的布局如下:Android 何时从布局(以编程方式)创建SurfaceView?,android,surfaceview,google-glass,android-framelayout,Android,Surfaceview,Google Glass,Android Framelayout,我想知道什么时候从布局中创建SurfaceView 这是一种从Google Glass上的LiveCard服务创建布局的场景,因此没有可以使用setContentView()设置此布局的活动 不过,我想知道怎样才能以编程方式创建SurfaceView 我的布局如下: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
<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>
但是,我无法创建SurfaceView,例如上面从未调用surfaceCreated()
要做到这一点,需要什么?您必须将内容视图设置为布局,并将表面视图添加到活动或主活动类的布局中
setContentView(R.layout.main);<---- basically points to and uses your xml
LinearLayout layout = (LinearLayout)findViewById(R.id.layout);<---- points to Layout defined in xml
layout.addView(new SurfaceView(this));<----adds SurfaceView to layout
setContentView(R.layout.main);<---- basically points to and uses your xml
LinearLayout layout = (LinearLayout)findViewById(R.id.layout);<---- points to Layout defined in xml
layout.addView(new SurfaceView(this));<----adds SurfaceView to layout
view surface = new SurfaceView(this);
SetContentView(surface);