2013-05-09 68 views
1

我试图在活动之间显示启动画面。为此,我使用加载ImageView的处理程序,然后在一段时间后将可见性设置为GONE。用动画加载屏幕后删除图像,Android

我想使它更加花哨,并使用loadAnimation为其设置动画效果。我遇到的问题是一旦处理程序结束了动画停止,但不会从屏幕上删除加载图像。相反,它只是作为整个活动的背景。

我想知道如何删除处理程序停止后的飞溅图像。

下面是我的代码:

private static final long SPLASHTIME = 3000; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main) 
    ImageView splash = (ImageView)findViewById(R.id.splashscreen); 
    final Animation a = AnimationUtils.loadAnimation(getBaseContext(),R.anim.progress_anim); 
    a.setDuration(1000); 
    splash.startAnimation(a); 
    new Handler().postDelayed(new Runnable(){ 
      @Override 
      public void run() { 
       a.cancel(); 
       splash.setVisibility(View.GONE); 

      } 
     }, SPLASHTIME); 
} 

XML飞溅的形象:

<ImageView 
    android:id="@+id/splashscreen" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:src="@drawable/loading_circle" 
    android:layout_gravity="center" 
    /> 
+0

在xml中移除图像并在oncreate中设置该图像。 – 2013-05-10 04:51:06

回答

0

就在全球范围内的OnCreate而不是申报飞溅()。

0

我认为你需要添加能见度:走在XML:ImageView的

,并ImageView的隐形

0

您需要

a.setFillAfter(true); 

添加到您的代码中你可运行结束。