2

我正在尝试使用带有一些文本的自定义 GLSurfaceView 来显示游戏中的分数。我已经根据某人在此处发布的帖子制作了统一的 xml 布局,但是当我尝试使用 setContentView 加载它时,应用程序崩溃了。调试后我发现它说“找不到源”。我已经重建了 R 文件,但这并没有帮助。作为参考,我扩展 GLSurfaceView 的类称为 GLView。任何帮助,将不胜感激。

 package org.kizik.WLTBO;


    import android.app.Activity;
    import android.os.Bundle;




    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.FrameLayout;
    import android.widget.LinearLayout;
    import android.widget.RelativeLayout;
    import android.widget.TextView;


    public class WholettheballoutActivity extends Activity {
       GLView view;



       @Override
       public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.score);
          view = (GLView) findViewById(R.id.mySurfaceView);

       // You can use a FrameLayout to hold the surface view
          /*FrameLayout frameLayout = new FrameLayout(this);
          frameLayout.addView(view);

          // Then create a layout to hold everything, for example a RelativeLayout
          RelativeLayout relativeLayout= new RelativeLayout(this);
          relativeLayout.addView(frameLayout);
          relativeLayout.addView(score);
          setContentView(relativeLayout);*/
       }

       @Override
       protected void onPause() {
           super.onPause();
           view.onPause();
       }

       @Override
       protected void onResume() {
           super.onResume();
           view.onResume();
       }
    }

使用 XML 文件名 score.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

    <TextView android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

    <org.kizik.WLTBO.GLView
        android:id="@+id/mySurfaceView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>        

</LinearLayout>
4

2 回答 2

3

如果您创建了一个带有单个参数 GLView(Context c) 的构造函数,则可能会发生这种情况,您需要创建另一个像这样 GLView(Context c, AttributeSet attrs) 的构造函数,所以如果您没有创建该构造函数,那么它就找不到来自类的 GLView,因为它的构造函数没有创建..!! 我认为您还没有创建该构造函数.. !!

 public GLview(Context context, AttributeSet attrs){

   super(context,attrs); }
于 2011-12-22T06:05:55.613 回答
0

问题出在自定义视图的 XML 声明中,应该是这样的:

 <org.kizik.WLTBO.GLView [other attributes]/>
于 2011-12-22T04:50:38.850 回答