「已注销」 2016-10-10 01:18 采纳率: 0%
浏览 5482

安卓动画如何停止?clearAnimation无效

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img1 = (ImageView) findViewById(R.id.point1);
img2 = (ImageView) findViewById(R.id.point2);
img3 = (ImageView) findViewById(R.id.point3);
img4 = (ImageView) findViewById(R.id.point4);
img5 = (ImageView) findViewById(R.id.point5);
img6 = (ImageView) findViewById(R.id.point6);
img7 = (ImageView) findViewById(R.id.point7);

    mTextView = (TextView) findViewById(R.id.loading);
    textView = (TextView) findViewById(R.id.stop);
    final ObjectAnimator img1xstart = ObjectAnimator.ofFloat(img1, "scaleX", 1.0f, 1.5f);
    final ObjectAnimator img1ystart = ObjectAnimator.ofFloat(img1, "scaleY", 1.0f, 1.5f);
    final ObjectAnimator img1xend = ObjectAnimator.ofFloat(img1, "scaleX", 1.5f, 1.0f);
    final ObjectAnimator img1yend = ObjectAnimator.ofFloat(img1, "scaleY", 1.5f, 1.0f);
    final ObjectAnimator img2xstart = ObjectAnimator.ofFloat(img2, "scaleX", 1.0f, 1.5f);
    final ObjectAnimator img2ystart = ObjectAnimator.ofFloat(img2, "scaleY", 1.0f, 1.5f);
    final ObjectAnimator img2xend = ObjectAnimator.ofFloat(img2, "scaleX", 1.5f, 1.0f);
    final ObjectAnimator img2yend = ObjectAnimator.ofFloat(img2, "scaleY", 1.5f, 1.0f);
    final ObjectAnimator img3xstart = ObjectAnimator.ofFloat(img3, "scaleX", 1.0f, 1.5f);
    final ObjectAnimator img3ystart = ObjectAnimator.ofFloat(img3, "scaleY", 1.0f, 1.5f);
    final ObjectAnimator img3xend = ObjectAnimator.ofFloat(img3, "scaleX", 1.5f, 1.0f);
    final ObjectAnimator img3yend = ObjectAnimator.ofFloat(img3, "scaleY", 1.5f, 1.0f);

    mTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            animSet = new AnimatorSet();
            animSet.play(img1xstart).with(img1ystart);
            animSet.setDuration(500);
            animSet.start();
            animSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    animSet2 = new AnimatorSet();
                    animSet2.play(img2xstart).with(img2ystart);
                    animSet2.play(img1xend).with(img1yend);
                    animSet2.setDuration(500);
                    animSet2.start();
                    animSet2.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            animSet3 = new AnimatorSet();
                            animSet3.play(img3xstart).with(img3ystart);
                            animSet3.play(img2xend).with(img2yend);
                            animSet3.setDuration(500);
                            animSet3.start();
                            animSet3.addListener(new AnimatorListenerAdapter() {
                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    animSet.start();
                                    animSet4 = new AnimatorSet();
                                    animSet4.play(img3xend).with(img3yend);
                                    animSet4.setDuration(500);
                                    animSet4.start();
                                }
                            });
                        }
                    });
                }
            });
        }
    });

    textView.setOnClickListener(new View.OnClickListener() {//
        @TargetApi(Build.VERSION_CODES.KITKAT)
        @Override
        public void onClick(View v) {
           /* animSet.pause();
            animSet2.pause();
            animSet3.pause();
            animSet4.pause();*/
           /* animSet.end();
            animSet2.end();
            animSet3.end();*/
            // animSet4.end();

//

img1.clearAnimation();
img2.clearAnimation();
img3.clearAnimation();

       /*     animSet.cancel();
            animSet2.cancel();
            animSet3.cancel();
            animSet4.cancel();*/

        }
    });
}

这是自己实验的小圆点循环加载的程序 是很麻烦 也还在学习中。。想请教一下这里我调用什么方法才能吧这个动画循环停止掉啊?求方法。。
自己试了很多都不行

  • 写回答

3条回答 默认 最新

  • Yang_Farley 2016-10-10 03:26
    关注

    animSet4.stop();

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条