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

Jul
  • 1,039
  • 3
  • 12
  • 20

1 Answers1

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.

Ragunath Jawahar
  • 19,513
  • 22
  • 110
  • 155
testingtester
  • 528
  • 4
  • 11
  • Thanks, it seems interessant but my view disappears at the end of the animation using your code snippet... – Jul Apr 21 '12 at 23:31
  • did you keep the fillAftertrue part – testingtester Apr 22 '12 at 00:02
  • 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? http://pastebin.com/Ki3BEtUL – Jul Apr 22 '12 at 12:28
  • It shouldn't be resizing anything but I've never moved a mapView. I'm not sure why that's happening – testingtester Apr 22 '12 at 12:47
  • I guess all kinds of layouts are resized. Indeed, the new width is the displayWidth minus newLeftMargin. – Jul Apr 22 '12 at 14:12