如何开始在同一时间两个动画在android系统? [英] How to start two animations at same time in android?

查看:170
本文介绍了如何开始在同一时间两个动画在android系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想在两个这些布局中,并在同一时间执行两个不同的动画两个线性布局。

I have two linear layouts which i want to perform two different animation on both of these layouts and at the same time.

现在它在连续的方式工作。即,完成一次后的另一个开始。

Now its working in sequential manner. i.e, after completing one its starting another.

这是我的code。

    Animation inFromRight = new TranslateAnimation(
                    Animation.RELATIVE_TO_PARENT, +0.0f,
                    Animation.RELATIVE_TO_PARENT, 0.0f,
                    Animation.RELATIVE_TO_PARENT, 0.0f,
                    Animation.RELATIVE_TO_PARENT, 0.0f);
            inFromRight.setDuration(500);
            inFromRight.setInterpolator(new AccelerateInterpolator());

    Animation outtoLeft = new TranslateAnimation(
                    Animation.RELATIVE_TO_PARENT, 0.0f,
                    Animation.RELATIVE_TO_PARENT, -1.0f,
                    Animation.RELATIVE_TO_PARENT, 0.0f,
                    Animation.RELATIVE_TO_PARENT, 0.0f);
            outtoLeft.setDuration(500);
            outtoLeft.setInterpolator(new AccelerateInterpolator());

    @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.menu:
                            mainLayout.startAnimation(outtoLeft);
                sideBar.startAnimation(inFromRight);                
                break;
            }
        }

outtoLeft.setAnimationListener(new AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                mainLayout
                        .setLayoutParams(new LayoutParams(
                                LayoutParams.FILL_PARENT,
                                LayoutParams.FILL_PARENT, 40));

            }
        });

在此先感谢!

推荐答案

我认为你需要使用AnimationSet

I think you need to use an AnimationSet

<一个href=\"http://developer.android.com/reference/android/view/animation/AnimationSet.html\">http://developer.android.com/reference/android/view/animation/AnimationSet.html

从DOC:

重新presents一组动画的应一起玩。每个动画的转型是由连成一个单一的转变。<​​/ code>

Represents a group of Animations that should be played together. The transformation of each individual animation are composed together into a single transform.

此链接排序显示了AnimationSet应该如何建立/执行的:<一href=\"http://groups.google.com/group/android-developers/browse_thread/thread/9df24ac25f01cee9/6e0eac7802a541e3\">http://groups.google.com/group/android-developers/browse_thread/thread/9df24ac25f01cee9/6e0eac7802a541e3

This link sort of shows how an AnimationSet is supposed to be built/executed: http://groups.google.com/group/android-developers/browse_thread/thread/9df24ac25f01cee9/6e0eac7802a541e3

这篇关于如何开始在同一时间两个动画在android系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆