我想用一些自定義的GLSurfaceView來覆蓋它,在遊戲中顯示分數。我做了一個統一的xml佈局,基於某些人在這裏發佈,但是當我嘗試加載它與setContentView應用程序崩潰。調試後,我發現它說「源無法找到」。我已經重建了R文件,但這沒有幫助。爲了參考,我的擴展GLSurfaceView的類被稱爲GLView。任何幫助,將不勝感激。setContentView說源找不到
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>
非常感謝!這永遠伴隨着我嘗試隨機的東西。那確實解決了它。 – 2011-12-22 22:51:17