Android:同时进行平移和旋转动画

发布于 2024-11-28 13:12:31 字数 2883 浏览 1 评论 0原文

我想以编程方式同时显示两个动画,而不是在 XML 文件中。它应该旋转和翻译 我怎样才能做到这一点?

请给我一些建议????

这是ma代码:>

ImageView snowImg1 = (ImageView) findViewById(R.id.snowimg1);
        snowImg1.setVisibility(0);
        ImageView snowImg2 = (ImageView) findViewById(R.id.snowimg2);
        snowImg2.setVisibility(0);
        ImageView snowImg3 = (ImageView) findViewById(R.id.snowimg3);
        snowImg3.setVisibility(0);
        ImageView snowImg4 = (ImageView) findViewById(R.id.snowimg4);
        snowImg4.setVisibility(0);
        ImageView snowImg6 = (ImageView) findViewById(R.id.snowimg6);
        snowImg6.setVisibility(0);
        ImageView snowImg5 = (ImageView) findViewById(R.id.snowimg5);
        snowImg5.setVisibility(0);

        View snowArray[] = {snowImg1, snowImg2, snowImg3, snowImg4, snowImg5, snowImg6};

        Animation snowMov7 = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f );
        snowMov7.setRepeatCount(Animation.INFINITE);
        Animation snowMov1 =  new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov1.setDuration(10000);
        Animation snowMov2 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.4f, Animation.RELATIVE_TO_PARENT, -0.1f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov2.setDuration(10100);
        Animation snowMov3 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, -0.1f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov3.setDuration(10200);
        Animation snowMov4 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.7f, Animation.RELATIVE_TO_PARENT, 0.2f, Animation.RELATIVE_TO_PARENT,-0.1f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov4.setDuration(10300);
        Animation snowMov5 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.6f, Animation.RELATIVE_TO_PARENT, 0.7f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov5.setDuration(10400);
        Animation snowMov6 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.9f, Animation.RELATIVE_TO_PARENT, 0.9f, Animation.RELATIVE_TO_PARENT, 0.05f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov6.setDuration(10500);

        Animation movArray[] = {snowMov1,snowMov2, snowMov3, snowMov4, snowMov5, snowMov6,snowMov7};

        for(int i=0;i<6;i++)
        {
            movArray[i].reset();
            movArray[i].setFillAfter(true);
            movArray[i].setAnimationListener(this);
            snowArray[i].startAnimation(movArray[i]);      
            snowArray[i].startAnimation(movArray[6]);
        }   

我们可以在程序中使用两次startAnimation吗???请帮助我?

I want to show two animation simultaneously programatically not in XML file.It should ROTATE and TRANSLATE
how can I do that?

Please suggest me some way??????

Here is ma code:>

ImageView snowImg1 = (ImageView) findViewById(R.id.snowimg1);
        snowImg1.setVisibility(0);
        ImageView snowImg2 = (ImageView) findViewById(R.id.snowimg2);
        snowImg2.setVisibility(0);
        ImageView snowImg3 = (ImageView) findViewById(R.id.snowimg3);
        snowImg3.setVisibility(0);
        ImageView snowImg4 = (ImageView) findViewById(R.id.snowimg4);
        snowImg4.setVisibility(0);
        ImageView snowImg6 = (ImageView) findViewById(R.id.snowimg6);
        snowImg6.setVisibility(0);
        ImageView snowImg5 = (ImageView) findViewById(R.id.snowimg5);
        snowImg5.setVisibility(0);

        View snowArray[] = {snowImg1, snowImg2, snowImg3, snowImg4, snowImg5, snowImg6};

        Animation snowMov7 = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f );
        snowMov7.setRepeatCount(Animation.INFINITE);
        Animation snowMov1 =  new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov1.setDuration(10000);
        Animation snowMov2 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.4f, Animation.RELATIVE_TO_PARENT, -0.1f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov2.setDuration(10100);
        Animation snowMov3 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, -0.1f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov3.setDuration(10200);
        Animation snowMov4 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.7f, Animation.RELATIVE_TO_PARENT, 0.2f, Animation.RELATIVE_TO_PARENT,-0.1f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov4.setDuration(10300);
        Animation snowMov5 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.6f, Animation.RELATIVE_TO_PARENT, 0.7f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov5.setDuration(10400);
        Animation snowMov6 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.9f, Animation.RELATIVE_TO_PARENT, 0.9f, Animation.RELATIVE_TO_PARENT, 0.05f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov6.setDuration(10500);

        Animation movArray[] = {snowMov1,snowMov2, snowMov3, snowMov4, snowMov5, snowMov6,snowMov7};

        for(int i=0;i<6;i++)
        {
            movArray[i].reset();
            movArray[i].setFillAfter(true);
            movArray[i].setAnimationListener(this);
            snowArray[i].startAnimation(movArray[i]);      
            snowArray[i].startAnimation(movArray[6]);
        }   

Can we use startAnimation twice in program???Please help me?

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

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

发布评论

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

评论(1

北斗星光 2024-12-05 13:12:31

我已经做到了使用 ANIMATIONSET 我们可以做到这一点。

AnimationSet snowMov1 = new AnimationSet(true);
        RotateAnimation rotate1 = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f );
        rotate1.setStartOffset(50);
        rotate1.setDuration(9500);
        snowMov1.addAnimation(rotate1);
        TranslateAnimation trans1 =  new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f);
        trans1.setDuration(12000);
        snowMov1.addAnimation(trans1);

这样我们就可以设置多个动画了。

I have done it Using ANIMATIONSET we can do this.

AnimationSet snowMov1 = new AnimationSet(true);
        RotateAnimation rotate1 = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f );
        rotate1.setStartOffset(50);
        rotate1.setDuration(9500);
        snowMov1.addAnimation(rotate1);
        TranslateAnimation trans1 =  new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f);
        trans1.setDuration(12000);
        snowMov1.addAnimation(trans1);

In this way we can made set for multiple animations.

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