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