how to make the animation clickable in android [duplicate]

≡放荡痞女 提交于 2019-12-06 05:05:00

During the entire animation, your view remains at the old location (location when the animation just started). It is just drawn in another spot. You'd have to move your animated view after your animation ends:

Register a listener to your animation. http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html

In your onAnimationEnd implementation, modify your Activity's layout so that it resembles the final state/layout of your animation.

Update after your comment:

The only way I see of doing this is by creating your own custom Animation in Java code and implementing your custom Animation's 'protected void applyTransformation(float interpolatedTime, Transformation t)' method. For example, in our app we have an animation that actually moves a View around instead of just drawing it at a different location. E.g. below is an example of an Animation that increases or decreases the actual height of a View:

public class ViewHeightAnimation extends Animation {
    private final View  view;
    private final float diffHeight;
    private final int   startHeight;

    public ViewHeightAnimation(View view, float diffHeight, int startHeight) {
        this.view = view;
        this.diffHeight = diffHeight;
        this.startHeight = startHeight;

        setDuration(200);
        setInterpolator(new AccelerateDecelerateInterpolator());
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        android.view.ViewGroup.MarginLayoutParams layoutParams = (android.view.ViewGroup.MarginLayoutParams)view.getLayoutParams();
        layoutParams.height = Math.round(startHeight + (diffHeight * interpolatedTime));
        view.setLayoutParams(layoutParams);
    }

    @Override
    public boolean willChangeBounds() {
        return true;
    }
}

Your Animation would be different, but would be using the 'getLayoutParams()' and 'setLayoutParams()' as well to modify the View's (ImageView's) position and change layoutParams.topMargin and layoutParams.leftMargin appropriately.

If you are not concerned about Android 2.x or lower, using the ObjectAnimator (3.0 or higher) or ViewPropertyAnimator (3.1 or higher) is a better solution, as was mentioned in other answer earlier.

Let me know if this helps you.

try like this:

final Animation animTranslate1 = AnimationUtils.loadAnimation(this,R.anim.translate);
animTranslate1.setFillAfter(true);
image01.startAnimation(animTranslate1);

If that does not work then you'll have to use the newer Property Animation framework (which was pointed out in the answer to your previous duplicate question)

See here to learn about it

The way you animate your imageView is only move its appearance, so actually your imageView is still at the old position. There's not an easy way to do what you want, with this type animations. You should consider to use ObjectAnimators ...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!