Android change layout dynamically

后端 未结 4 1615
既然无缘
既然无缘 2020-12-02 17:45

I have situation where I want to change layout of activity after 3 seconds. Ho can I do that? For example application starts with splashscreen that will run for 3 seconds th

4条回答
  •  旧巷少年郎
    2020-12-02 18:21

    I did this using only one xml layout. I just put an extra RelativeLayout in it that represents my intro screen then I use a fadeOut Animation on it and then call .setVisibility(View.GONE).

    This is part of my main.xml layout file

    
    
            
            
        
    

    Then inside my activity I have this:

    introLayout = (RelativeLayout) findViewById(R.id.introLayout);
    Animation fadeOutAnim = AnimationUtils.loadAnimation(MyActivity.this, R.anim.fadeout);
    introLayout.startAnimation(fadeOutAnim);
    introLayout.setVisibility(View.GONE);
    

    You could make this run after 3 seconds by putting the startAnimation(), and the setVisibility inside of a runnable and using postDelayed() as markus mentioned. Do consider doing some work while this intro layout is on the screen though, so its not just a 3 second delay for the user. Perhaps check to see if the running version of the application is the current version or not.

    EDIT: You'll need to add the fadout.xml file to /res/anim/ (create the anim directory if it doesn't exist). Here is an example.

    fadeout.xml

    
    
    
    

提交回复
热议问题