Android 如何处理GLSURFACHEVIEW的暂停/恢复

Android 如何处理GLSURFACHEVIEW的暂停/恢复,android,opengl-es,Android,Opengl Es,当GLSURFACHEVIEW嵌入到布局中时,例如 <FrameLayout android:id="@+id/framelay" android:layout_width="fill_parent" android:layout_height="fill_parent"> <com.nelsondev.myha3ogl.M3View android:layout_width="fill_parent" android:layout

当GLSURFACHEVIEW嵌入到布局中时,例如

  <FrameLayout
  android:id="@+id/framelay"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
     <com.nelsondev.myha3ogl.M3View
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"/>
  </FrameLayout> 

然后,当布局膨胀时,它将使用签名为GLSurfaceView(Context-Context,AttributeSet-attrs)的构造函数自动构造。所以它不是在Activity类中直接声明或实例化的

Android文档说明活动的onPause/onResume必须调用SurfaceView的onPause/onResume。我该怎么做?即,使布局膨胀的活动如何访问GLSURFACHEVIEW对象以进行这些调用

编辑:这是针对Android 2.2的


提前感谢

在XML布局中,通过添加name属性为SurfaceView命名:

<com.nelsondev.myha3ogl.M3View
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/my_surfaceView1"/>
最后,在曲面视图的实现中,重写onPause()/onResume(),并将活动暂停/恢复时需要执行的任何代码放在其中。还记得在曲面视图中调用super.onPause()/super.onResume()
编辑:为了澄清,您可以在任何ViewGroup对象上使用
findViewById()
方法来查找该ViewGroup中的子视图:

MyActivity extends Activity{

    public void onCreate(Bundle bundle){

        FrameLayout myFrameLayout = (FrameLayout)getLayoutInflater().inflate(R.layout.graphics, null, false);
        TextView myView = (TextView)myFrameLayout.findViewById(R.id.textView1);

        if(myView!=null){
            myView.setText("about to be removed");
            myFrameLayout.removeView(myView);
        }

        setContentView(myFrameLayout);


    }
}
或者
findViewById()
也是活动中的一个方法,它将在使用
setContentView()设置的布局中查找任何视图


谢谢我已经多次将findViewById用于按钮和编辑控件等,但我没有意识到我可以将它用于像这样的自定义类。它工作得很好;再次感谢!
MyActivity extends Activity{

    public void onCreate(Bundle bundle){

        FrameLayout myFrameLayout = (FrameLayout)getLayoutInflater().inflate(R.layout.graphics, null, false);
        TextView myView = (TextView)myFrameLayout.findViewById(R.id.textView1);

        if(myView!=null){
            myView.setText("about to be removed");
            myFrameLayout.removeView(myView);
        }

        setContentView(myFrameLayout);


    }
}
MyActivity extends Activity{

    public void onCreate(Bundle bundle){
        setContentView(R.layout.graphics);
        // where the xml file in your question is called graphics.xml    
        com.nelsondev.myha3ogl.M3View myGLSurfaceView = (com.nelsondev.myha3ogl.M3View)findViewById(R.id.my_surfaceView1);
        FrameLayout myFrameLayout = (FrameLayout)findViewById(R.id.framelay);
    }
}