2011-09-23 33 views
4

我試圖將View插入佔用全屏的另一視圖後面,然後刪除前面的視圖以顯示剩餘的唯一視圖。在功能上,一切都按預期工作,但問題是,當我呼叫View.addView()添加第二個視圖,指定將其添加到索引0,因此它在第一個視圖後面,屏幕閃爍。這幾乎就好像視圖實際上是在第一個視圖前添加了幾分之一秒,然後當它被移動到後面時它又被隱藏了。將視圖添加到現有視圖背後的相對佈局會導致屏幕閃爍

下面是我在做什麼:

當活動被創建我添加ImageViewRelativeLayout,使RelativeLayout實例活動的內容視圖:

protected void onCreate(Bundle bundle) { 

    super.onCreate(bundle); 

    m_layout = new RelativeLayout(this); 
    m_layout.setBackgroundColor(Color.BLACK); 

    m_splashImage = new ImageView(this); 
    m_splashImage.setImageResource(R.drawable.splash); 
    m_splashImage.setScaleType(ScaleType.FIT_XY); 

    m_layout.addView(m_splashImage, 
     new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, 
     RelativeLayout.LayoutParams.FILL_PARENT)); 

    setContentView(m_layout); 
} 

活動是開始,我創建並將GLSurfaceView添加到位於索引0的RelativeLayout,因此它位於ImageView後面:

protected void onStart() { 

    super.onStart(); 

    m_layout.addView(new MyGLSurfaceView(), 0, 
     new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, 
     RelativeLayout.LayoutParams.FILL_PARENT)); 
} 

後來,在完成所有加載並且GLSurfaceView準備好連續渲染後, 飛濺ImageView被刪除並清理完畢。

public void hideSplashScreen() { 

    if (m_splashImage != null) { 
     m_layout.removeView(m_splashImage); 
     m_splashImage = null; 
    } 
} 

是否有更好的方法可以做到這一點並不需要創建的在onStart()稱爲GLSurfaceView過嗎?

回答

0

您是否嘗試過使用view.setVisibility(View.GONE)來加入後面的視圖?當然,在你添加它之前。