View animation doesn't change touch area
Asked Answered
C

1

5

After a TranslateAnimation, the OnClickListener on view translated is not translated. I tried overriding getHitRect in a custom LinearLayout but without success. I also tried to use a touchdelegate and all other suggestions found on the whole internet without success :)

TranslateAnimation open = new TranslateAnimation(0, displayWidth - ivTimelineWidth, 0, 0);
open.setDuration(1000);   
open.setFillAfter(true);
llMapContent.startAnimation(open);

Please help me :)

Julien

Conurbation answered 21/4, 2012 at 20:47 Comment(0)
A
7

If I am understanding your problem correctly, you want to click on something after it's been translated and it's not registering the onTouch of the something. This problem is occurring because TranslateAnimation does not actually move the object, just the pixels on the screen. You would call the onTouch if touch the area where the item was. To actually move the object rather than the pixels on the screen I recommend using this code snippet:

MarginLayoutParams marginParams = new MarginLayoutParams(someobject.getLayoutParams());
marginParams.setMargins(xx, xx, xx, xx);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams);
someobject.setLayoutParams(layoutParams); 

You should probably place this in the onAnimationEnd or onAnimationStart methods. Hope this helps.

Abscond answered 21/4, 2012 at 21:24 Comment(5)
Thanks, it seems interessant but my view disappears at the end of the animation using your code snippet...Conurbation
did you keep the fillAftertrue partAbscond
Ok, I got it working with this code. BUT, at the end of the anim it blinks because the mapview is resized when changing the leftMargin. Do you have a tip to avoid resizing? pastebin.com/Ki3BEtULConurbation
It shouldn't be resizing anything but I've never moved a mapView. I'm not sure why that's happeningAbscond
I guess all kinds of layouts are resized. Indeed, the new width is the displayWidth minus newLeftMargin.Conurbation

© 2022 - 2024 — McMap. All rights reserved.