TranslateAnimated ImageView not clickable after animation [Android]
Asked Answered
R

1

8

I have 2 ImageViews that I translate from the top of the screen to the bottom. these views are infalted from xml and the animation is added from java code. The animation works perfectly, but the onClickListener I added in java code doesn't seem to work. I used fillAfter attribute of the animation to make the iamges stay at their arrival after the translation, but THESE images aren't clickable anymore... However, their position before translation remains clickable... I can't see the logic of this. Could anyone give me some piece of advice about that?

Rancorous answered 3/8, 2010 at 14:15 Comment(3)
Ok, found my answer here : #2126194 now I just need to set its params properly to get its position right...Rancorous
However, this does not seem to be compatible with setFillAfter. I add to remove it to get it to work.Rancorous
I had this problem, and I solved it after some research. [Here you can find an answer][1] [1]: #18333769Beckner
B
14

This is because Animations affects only the drawing of widget. However, The real Location is not affected -It is still in the previous one-.

To overcome this problem, you need to update the layout parameters of the ImageView manually by installing an animation listener as follows:

Animation.setAnimationListener(new AnimationListener() {
        public void onAnimationStart(Animation arg0) {

        }

        public void onAnimationRepeat(Animation arg0) {
            //TODO Auto-generated method stub
        }

        public void onAnimationEnd(Animation arg0) {
            android.widget.LinearLayout.LayoutParams params = new LayoutParams(
            android.widget.LinearLayout.LayoutParams.FILL_PARENT,
            android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
            params.topMargin = addLocationButton.getTop()-100;

            ImageView.setLayoutParams(params);
        }
        });
Bosun answered 24/1, 2011 at 11:21 Comment(2)
No good, because after the animation in onAnimationEnd, when the image get the position from "setLayoutParams(params);" then I see a flicker. I add that is difficult to set the topMargin from the percentage of the property toYDeltaPatmos
To remove the flicker you can use animation.reset(); <my view>.clearAnimation();Advertent

© 2022 - 2024 — McMap. All rights reserved.