观看动画不会改变触摸区域区域、动画

2023-09-08 00:14:02 作者:疯人院疯人疯语

一个TranslateAnimation后,对视图翻译OnClickListener未翻译。我想在一个定制的LinearLayout但没有成功覆盖getHitRect。我还试图用一个touchdelegate和所有其他的建议,整个互联网上找到没有成功:)

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);

请帮我:)

朱利安

推荐答案

如果我理解正确你的问题,你想它被翻译,它不是注册的东西onTouch后的东西点击。这个问题发生,因为TranslateAnimation实际上并不移动对象,在画面上只的像素。你会调用onTouch如果触摸那里的项目是该地区。要真正移动,而不是屏幕上的像素我建议使用此code片段对象:

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); 

您也许应该把这个在 onAnimationEnd onAnimationStart 方法。希望这有助于。

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