Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 何时从布局(以编程方式)创建SurfaceView?_Android_Surfaceview_Google Glass_Android Framelayout - Fatal编程技术网

Android 何时从布局(以编程方式)创建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"

我想知道什么时候从布局中创建SurfaceView

这是一种从Google Glass上的LiveCard服务创建布局的场景,因此没有可以使用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>
但是,我无法创建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);