本文介绍了使用Animation和onAnimationEnd Listener时的Android闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个ImageButton,当向左填充时会变动画,像这样:

I have 3 ImageButtons which are animated when Filling to left, like this:

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
    ImageButton top;
    ImageButton left;
    ImageButton right;

    top     = meMap.get("top");
    left    = meMap.get("left");
    right   = meMap.get("right");

    goLeft =
            new TranslateAnimation(0, -(top.getLeft() - left.getLeft()), 0, -(top.getTop() - left.getTop()));

    goRight =
            new TranslateAnimation(0, -(left.getLeft() - right.getLeft()), 0, -(left.getTop() - right.getTop()));

    goTopFromRight =
            new TranslateAnimation(0, top.getLeft() - right.getLeft(), 0, top.getTop() - right.getTop());


    goRight.setAnimationListener(this);

    if (velocityX<-500)
    {
        System.out.println("aaaa "+"ScrollLeft");


        goLeft.setDuration(500);
        goLeft.setFillAfter(true);
        goLeft.setFillAfter(true);
        top.startAnimation(goLeft);

        goRight.setDuration(500);
        goRight.setFillAfter(true);
        goRight.setFillAfter(true);
        left.startAnimation(goRight);

        goTopFromRight.setDuration(500);
        goTopFromRight.setFillAfter(true);
        goTopFromRight.setFillAfter(true);
        right.startAnimation(goTopFromRight);

    }

现在,我有一个像这样的onanimationEnd侦听器:

Now, I have an onanimationEnd listener like this:

public void onAnimationEnd(Animation animation) {
    ImageButton top;
    ImageButton left;
    ImageButton right;

    top     = meMap.get("top");
    left    = meMap.get("left");
    right   = meMap.get("right");



    top.clearAnimation();
    left.clearAnimation();
    right.clearAnimation();


    RelativeLayout.LayoutParams layoutLeft =
                new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);

    layoutLeft.addRule(RelativeLayout.ALIGN_BOTTOM,R.id.CenterTextView);
    layoutLeft.addRule(RelativeLayout.LEFT_OF,R.id.CenterTextView);
    top.setLayoutParams(layoutLeft);


    RelativeLayout.LayoutParams layoutRight =
            new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);

    layoutRight.addRule(RelativeLayout.ALIGN_BOTTOM,R.id.CenterTextView);
    layoutRight.addRule(RelativeLayout.RIGHT_OF,R.id.CenterTextView);
    left.setLayoutParams(layoutRight);

    RelativeLayout.LayoutParams layoutTop =
            new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);

    layoutTop.addRule(RelativeLayout.CENTER_VERTICAL,RelativeLayout.TRUE);
    layoutTop.addRule(RelativeLayout.CENTER_HORIZONTAL,RelativeLayout.TRUE);
    right.setLayoutParams(layoutTop);


    meMap.put("top", right);
    meMap.put("left", top);
    meMap.put("right", left);

}

问题是当我制作动画(goRight除外)时,我的图标闪烁了片刻.我不知道该如何解决.请帮忙.

The problem is that when I am doing the animations (except goRight), my icons are Flickering for a litle moment. I don't know how to resolve this. Please Help.

推荐答案

安娜,我想您已经在这里阅读了我的答案

Ana, I think you have already read my answers here

在动画后,Android TranslateAnimation会重置

android动画未在onAnimationEnd中完成

我也回答了您的评论,基本上是在执行mAnimation.setAnimationListener方法内部的功能之前,您需要创建自定义ImageButton并将功能放在其中

I had also replied to your comment, basically in stead of doing the functionality inside the mAnimation.setAnimationListener method, you need to create custom ImageButtons and put the functionality there

public Class myImageButton extends ImageButton {
@Override
    protected void onAnimationEnd() {
        super.onAnimationEnd();
        //Functionality here
    }

这篇关于使用Animation和onAnimationEnd Listener时的Android闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-19 09:44