几个视图的同时动画

时间:2016-07-19 08:35:26

标签: java android android-animation

每次用户触摸屏幕中的屏幕时,都会显示新的Views,当View出现新View时,此private class MyGestureListener extends GestureDetector.SimpleOnGestureListener { @Override public boolean onDown(MotionEvent e) { switch (e.getAction()) { case MotionEvent.ACTION_DOWN: int x = (int) e.getX(); int y = (int) e.getY(); draw = new DrawView(getActivity(), 1, String.valueOf(xcoordList.size())); drawViewList.add(draw); progressBar.addView(draw); progressBar.invalidate(); drawViewList.get(drawViewList.size()-1).animate().translationXBy(-360f).setDuration(1000); Runnable runnable = new Runnable() { @Override public void run() { CountDownTimer timer = new CountDownTimer(System.currentTimeMillis() + 2000 - timeList.get(0), 1000) { int j = 3; @Override public void onTick(long millisUntilFinished) { final DrawView drawView = drawViewList.get(drawViewList.size()-1); drawView.animate().translationXBy((-720f)/j).setDuration(1000); j++; @Override public void onFinish() { } }.start(); } }; getActivity().runOnUiThread(runnable); } 中的每一个都应向左移动,前一个视图的动画停止,如何同时动画它们?

{{1}}

1 个答案:

答案 0 :(得分:0)

我使用的解决方案,我更改了这行代码:

drawView.animate().translationXBy((-720f)/j).setDuration(1000);

有:

drawView.animate().translationXBy((-720f)/j)
                                        .setDuration(1000).setListener(new Animator.AnimatorListener() {
                                    @Override
                                    public void onAnimationStart(Animator animation) {
                                        j++;
                                    }

                                    @Override
                                    public void onAnimationEnd(Animator animation) {
                                        drawView.animate().translationXBy((-720f) / j).setDuration(1000);
                                    }

                                    @Override
                                    public void onAnimationCancel(Animator animation) {

                                    }

                                    @Override
                                    public void onAnimationRepeat(Animator animation) {

                                    }
                                });