首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >误差膨胀GLSurfaceView

误差膨胀GLSurfaceView
EN

Stack Overflow用户
提问于 2014-03-14 00:28:31
回答 2查看 2.3K关注 0票数 0

我正在尝试将我的GLSurfaceView和其他UI元素一起设置为xml布局,并在LogCat中不断获得错误膨胀类com.vi.cubo01.MyGLSurfaceView。

以下是java代码:

代码语言:javascript
复制
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());
        }
    }

以及xml:

代码语言:javascript
复制
<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"
     />

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-03-14 16:09:44

如果要从XML中膨胀,则除了已经拥有的(Context)构造函数之外,还需要包含(Context,AttributeSet)构造函数。这是因为布局膨胀器需要调用它来处理您在XML中指定的属性,例如layout_width和layout_height。

代码语言:javascript
复制
public MyGLSurfaceView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setEGLContextClientVersion(2);
    setRenderer(new CustomRenderer());
}
票数 5
EN

Stack Overflow用户

发布于 2020-05-20 14:38:17

Kotlin版本:

代码语言:javascript
复制
class MyGLSurfaceView(context: Context,
                          attributes: AttributeSet? = null): GLSurfaceView(context, attributes) {
// ...
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22393845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档