Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View animation doesn't change touch area

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

like image 237
Jul Avatar asked Apr 21 '12 20:04

Jul


1 Answers

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.

like image 83
testingtester Avatar answered Oct 24 '22 11:10

testingtester