图像视图动画

发布于 2024-11-06 02:40:29 字数 2643 浏览 1 评论 0原文

我正在研究图像动画的顺序。这是我的 java 活动文件。

对于每个图像视图,我使用 fadein、fadeout xml。但我无法以线程方式一一获取该动画。

package com.cardio.android;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class guide extends Activity {

       //create name of animation
    Animation myFadeInAnimation;
    Animation myFadeOutAnimation;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

     //grab the imageview and load the animations
        ImageView myImageView = (ImageView) findViewById(R.id.imageView1);
        ImageView myImageView1 = (ImageView) findViewById(R.id.imageView2);
        ImageView myImageView2 = (ImageView) findViewById(R.id.imageView3);
        ImageView myImageView3 = (ImageView) findViewById(R.id.imageView4);
        ImageView myImageView4 = (ImageView) findViewById(R.id.imageView5);
        Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein);
        Animation myFadeOutAnimation = AnimationUtils.loadAnimation(this, R.anim.fadeout);
        Animation myFadeInAnimation1 = AnimationUtils.loadAnimation(this, R.anim.fadein1);
        Animation myFadeOutAnimation1 = AnimationUtils.loadAnimation(this, R.anim.fadeout1);
        Animation myFadeInAnimation2 = AnimationUtils.loadAnimation(this, R.anim.fadein2);
        Animation myFadeOutAnimation2 = AnimationUtils.loadAnimation(this, R.anim.fadeout2);
        Animation myFadeInAnimation3 = AnimationUtils.loadAnimation(this, R.anim.fadein3);
        Animation myFadeOutAnimation3 = AnimationUtils.loadAnimation(this, R.anim.fadeout3);
        Animation myFadeInAnimation4 = AnimationUtils.loadAnimation(this, R.anim.fadein4);
        Animation myFadeOutAnimation4 = AnimationUtils.loadAnimation(this, R.anim.fadeout4);



    //fade it in, and fade it out. 
        myImageView.startAnimation(myFadeInAnimation);
        myImageView.startAnimation(myFadeOutAnimation);
        myImageView1.startAnimation(myFadeInAnimation1);
        myImageView1.startAnimation(myFadeOutAnimation1);
        myImageView2.startAnimation(myFadeInAnimation2);
        myImageView2.startAnimation(myFadeOutAnimation2);
        myImageView3.startAnimation(myFadeInAnimation3);
        myImageView3.startAnimation(myFadeOutAnimation3);
        myImageView4.startAnimation(myFadeInAnimation4);
        myImageView4.startAnimation(myFadeOutAnimation4);
        }
    }  

I am working on sequential order of image animations. Here is my java activity file.

For each imageview i am using fadein, fadeout xml. But i could not able to get this animations one by one in a threading manner.

package com.cardio.android;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class guide extends Activity {

       //create name of animation
    Animation myFadeInAnimation;
    Animation myFadeOutAnimation;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

     //grab the imageview and load the animations
        ImageView myImageView = (ImageView) findViewById(R.id.imageView1);
        ImageView myImageView1 = (ImageView) findViewById(R.id.imageView2);
        ImageView myImageView2 = (ImageView) findViewById(R.id.imageView3);
        ImageView myImageView3 = (ImageView) findViewById(R.id.imageView4);
        ImageView myImageView4 = (ImageView) findViewById(R.id.imageView5);
        Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein);
        Animation myFadeOutAnimation = AnimationUtils.loadAnimation(this, R.anim.fadeout);
        Animation myFadeInAnimation1 = AnimationUtils.loadAnimation(this, R.anim.fadein1);
        Animation myFadeOutAnimation1 = AnimationUtils.loadAnimation(this, R.anim.fadeout1);
        Animation myFadeInAnimation2 = AnimationUtils.loadAnimation(this, R.anim.fadein2);
        Animation myFadeOutAnimation2 = AnimationUtils.loadAnimation(this, R.anim.fadeout2);
        Animation myFadeInAnimation3 = AnimationUtils.loadAnimation(this, R.anim.fadein3);
        Animation myFadeOutAnimation3 = AnimationUtils.loadAnimation(this, R.anim.fadeout3);
        Animation myFadeInAnimation4 = AnimationUtils.loadAnimation(this, R.anim.fadein4);
        Animation myFadeOutAnimation4 = AnimationUtils.loadAnimation(this, R.anim.fadeout4);



    //fade it in, and fade it out. 
        myImageView.startAnimation(myFadeInAnimation);
        myImageView.startAnimation(myFadeOutAnimation);
        myImageView1.startAnimation(myFadeInAnimation1);
        myImageView1.startAnimation(myFadeOutAnimation1);
        myImageView2.startAnimation(myFadeInAnimation2);
        myImageView2.startAnimation(myFadeOutAnimation2);
        myImageView3.startAnimation(myFadeInAnimation3);
        myImageView3.startAnimation(myFadeOutAnimation3);
        myImageView4.startAnimation(myFadeInAnimation4);
        myImageView4.startAnimation(myFadeOutAnimation4);
        }
    }  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦行七里 2024-11-13 02:40:29

您需要使用 onAnimationEnd 事件并在其中触发下一个动画。您可以创建一个循环来执行此操作,也可以将它们嵌套在一起:

        myAnimation.setAnimationListener(new AnimationListener() {
                public void onAnimationEnd(Animation animation) {

                   //here enter code for the next animation...

                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onAnimationStart(Animation animation) {
                    // TODO Auto-generated method stub

                } 
            }); 

You need to use onAnimationEnd event and in it trigger the next animation. You can create a loop to do it or just nest them into each other:

        myAnimation.setAnimationListener(new AnimationListener() {
                public void onAnimationEnd(Animation animation) {

                   //here enter code for the next animation...

                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onAnimationStart(Animation animation) {
                    // TODO Auto-generated method stub

                } 
            }); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文