我试图将 GLSurfaceView 与其他 UI 元素一起设置在 xml 布局上,但在 LogCat 中不断出现错误,导致类 com.vi.cubo01.MyGLSurfaceView 膨胀。
这是java代码:
super.onCreate(savedInstanceState);
mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.vistaGLSuperficie)
setContentView(R.layout.activity_main);
}
@Override
protected void onResume()
{
super.onResume();
mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.vistaGLSuperficie);
mGLSurfaceView.onResume();
}
@Override
protected void onPause()
{
super.onPause();
mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.vistaGLSuperficie);
mGLSurfaceView.onPause();
}
class MyGLSurfaceView extends GLSurfaceView {
public MyGLSurfaceView(Context context) {
super(context);
setEGLContextClientVersion(2);
setRenderer(new CustomRenderer());
}
}
Run Code Online (Sandbox Code Playgroud)
和 XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0" />
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.vi.cubo01.MyGLSurfaceView
android:id="@+id/vistaGLSuperficie"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Run Code Online (Sandbox Code Playgroud)
如果您从 XML 进行扩充,除了已有的 (Context) 构造函数之外,您还需要包含 (Context, AttributeSet) 构造函数。这是因为布局充气器需要调用它来处理您在 XML 中指定的属性,例如layout_width 和layout_height。
public MyGLSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
setEGLContextClientVersion(2);
setRenderer(new CustomRenderer());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2370 次 |
| 最近记录: |