【发布时间】:2011-09-23 21:49:23
【问题描述】:
我试图在另一个占据全屏的视图后面插入View,然后删除前面的视图以显示唯一剩余的视图。从功能上讲,一切都按预期工作,但问题是当我调用 View.addView() 来添加第二个视图时,指定在索引 0 处添加它,因此它位于第一个视图的后面,屏幕闪烁。几乎就好像视图实际上被添加到第一个视图的前面几分之一秒,然后当它移到它后面时它又被隐藏了。
这就是我正在做的事情:
创建 Activity 后,我将 ImageView 添加到 RelativeLayout 并让 RelativeLayout 实例成为 Activity 的内容视图:
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);
}
Activity启动时,我创建了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?
【问题讨论】:
标签: android android-layout android-view