2012-05-15 4 views
0

내 설정은 다음과 같습니다 : TabHost는 하나의 GLSurfaceView를 내용으로하는 두개의 자식 활동을 가지고 있습니다. 물론 두 액티비티는 onPause() 및 onResume() 이벤트를 GLSurfaceView로 전달합니다.TabHost 내에 GLSurfaceView를 포함하는 다중 활동 구성하기

첫 번째 활동은 예상대로 작동하지만 다른 탭으로 전환해도 시각적 효과는 없습니다. LogCat은 onSurfaceCreated(), onSurfaceChanged() 및 onSurfaceDraw()가 모두 GLSurfaceView 인스턴스에서 모두 예상대로 호출됨을 보여줍니다.

"수정"은 onPause() 및 onResume()에서 각각 setVisibility (View.INVISIBLE/VISIBLE)를 사용하여 각 GLSurfaceView의 가시성을 설정하는 것입니다. 이로 인해 올바른보기가 표시되지만 탭을 변경할 때 깜박임 효과가 발생하는 단점이 있습니다. 이것은 특히 GLSurfaceView가 더 많은 일을 할 때 분명합니다.

본질적으로 GLSurfaceView의 가시성을 설정하지 않으려면 어떻게해야합니까?

TabActivity :

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> 
,

답변

0

또 다른 해결 방법은 항상 볼 수있는 단일 GLSurfaceView를 사용하고 표시되는 내용을 전환하는 것입니다.

+0

어떻게 활동간에 GLSurfaceView를 공유하겠습니까? 내가 아는 한 당신은보기에서 부모 활동을 '변경'할 수 없습니다. (http://stackoverflow.com/questions/7813306/how-can-i-pass-image-view-between-activities-in- android) – Rodskjegg

+0

아, 그 정도면 충분합니다. 나는 그들이 실제 활동이 아니라 단지 어린이 배치라고 생각했습니다. –

관련 문제