私のセットアップは次のとおりです。TabHost には 2 つの子アクティビティがあり、それぞれがコンテンツとして単一の GLSurfaceView を持ちます。もちろん、2 つのアクティビティは onPause() および onResume() イベントを GLSurfaceViews に転送しています。
最初のアクティビティは期待どおりに機能しますが、他のタブに切り替えても視覚的な影響はありません。LogCat は、onSurfaceCreated()、onSurfaceChanged()、および onSurfaceDraw() の両方が両方の GLSurfaceView インスタンスで期待どおりにすべて呼び出されていることを示しています。
「修正」は、onPause() と onResume() でそれぞれ setVisibility(View.INVISIBLE/VISIBLE) を使用して、各 GLSurfaceView の可視性を設定することです。これにより、正しいビューが表示されますが、タブを変更するときにちらつき効果が発生するという欠点があります。これは、GLSurfaceView がより多くの仕事をしている場合に特に顕著です。
基本的に、GLSurfaceViews の VISIBILITY を設定する必要がないようにするにはどうすればよいですか?
タブアクティビティ:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainactivity);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
// First Vortex view
intent = new Intent().setClass(this, VortexActivity.class);
spec = tabHost.newTabSpec("A")
.setIndicator("A")
.setContent(intent);
tabHost.addTab(spec);
// Second Vortex view
intent = new Intent().setClass(this, VortexActivity.class);
spec = tabHost.newTabSpec("B")
.setIndicator("B")
.setContent(intent);
tabHost.addTab(spec);
}
子供の活動:
public class VortexActivity extends Activity {
private GLSurfaceView view;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view = new GLSurfaceView(this);
view.setRenderer(new VortexRenderer());
setContentView(view);
}
@Override
public void onResume() {
super.onResume();
view.onResume();
//view.setVisibility(View.VISIBLE);
}
@Override
public void onPause() {
super.onPause();
view.onPause();
//view.setVisibility(View.INVISIBLE);
}
}
レンダラー:
public class VortexRenderer implements GLSurfaceView.Renderer {
public void onSurfaceCreated(GL10 glArgument, EGLConfig config) {
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
}
public void onDrawFrame(GL10 gl) {
long ms = System.currentTimeMillis() % 2000;
if(ms > 1000)
ms = 1000 - (ms - 1000);
float intensity = ms / 500.0f;
gl.glClearColor(intensity, intensity, intensity, 1.0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
}
}
レイアウト:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="0dp" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="0dp" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:padding="0dp" />
</LinearLayout>