【问题标题】:Animation on startup启动动画
【发布时间】:2015-11-24 15:15:36
【问题描述】:

在我的初始屏幕上,我想让 TextView 淡入,5 秒后淡出,在它淡出后我希望它打开一个新的 xml 文件。有人可以帮我吗?我对编码有点陌生,所以也许一些代码会很棒!亲切的问候!

【问题讨论】:

  • 如果您不熟悉编码,搜索您自己进行的代码示例对您的帮助最大。尤其是当您可以比较不同的解决方案时。

标签: android animation textview startup


【解决方案1】:

在 oncreate() 中试试这个:

     //First start animation for fadein
    Animation animation = AnimationUtils.loadAnimation(this,R.anim.abc_fade_in);
    yourtextView.startAnimation(animation);

    // The thread to wait for 5 seconds
    mSplashThread =  new Thread(){
        @Override
        public void run(){
            try {
                 Thread.sleep(5000);
            }
            catch(InterruptedException ex){                    
            } finally{
            //start animation for fadeout after 5 seconds
            Animation animation = AnimationUtils.loadAnimation(YourClass.this,R.anim.abc_fade_out);
            yourtextView.startAnimation(animation);
            //Start next activity
            Intent intent = new Intent(YourClass.this,MainActivity.class);
            startActivity(intent);  
            }     
        }
    };
    mSplashThread.start();

【讨论】:

  • 感谢您的回复!我没有收到任何错误,除非您定义动画。在 (this,R.anim.abc_fade_out) 中,Android Studio 通过 'this' 给出一个错误,然后它说:错误的第一个参数类型。发现:'java.lang.Thread',要求:'android.content.Context'在AnimationUtils中的loadAnimation(android.content.Context,int)不能应用于(匿名java.lang.Thread,int)任何想法如何解决这个?
  • 因为它在 run() 方法中,而不是 'this',使用 'YourClassName.this'
猜你喜欢
  • 1970-01-01
  • 2019-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-03
相关资源
最近更新 更多