TranslateAnimation 在 Imageview 之外剪切图像
我正在使用 TranslateAnimation 在移动图像后将其居中,问题是,如果动画开始时图像的一部分位于视图之外,则在动画过程中它将不可见:
我的代码:
TranslateAnimation trans = new TranslateAnimation(0, deltaX, 0,
deltaY);
trans.setDuration(250);
trans.setInterpolator(new AccelerateInterpolator(1.0f));
this.startAnimation(trans);
编辑:
是先将图像居中,然后将动画从原始位置绘制到中心,如下所示:
setVisibility(INVISIBLE);
//A void that centers the image inside the view
center(true, true);
TranslateAnimation trans = new TranslateAnimation(-deltaX, 0,-deltaY, 0);
trans.setDuration(250);
trans.setInterpolator(new AccelerateInterpolator(1.0f));
this.startAnimation(trans);
setVisibility(VISIBLE);
I am using TranslateAnimation to center my image after it has been moved, the problem is if part of the image is outside of the view when the animation starts it will not be visible during the animation:
My code:
TranslateAnimation trans = new TranslateAnimation(0, deltaX, 0,
deltaY);
trans.setDuration(250);
trans.setInterpolator(new AccelerateInterpolator(1.0f));
this.startAnimation(trans);
Edit:
Solved it by first centering the image and then drawing the animation from its original position to the center as follows:
setVisibility(INVISIBLE);
//A void that centers the image inside the view
center(true, true);
TranslateAnimation trans = new TranslateAnimation(-deltaX, 0,-deltaY, 0);
trans.setDuration(250);
trans.setInterpolator(new AccelerateInterpolator(1.0f));
this.startAnimation(trans);
setVisibility(VISIBLE);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,android 不会绘制屏幕上不可见的视图部分。将动画应用于视图时,只有像素会发生移动,而视图仍保留在旧位置,这应该是问题所在,因为只有图像的可见像素才会发生移动。
我的想法是添加一个动画监听器并覆盖animationStart方法并将视图手动添加到正确的位置,或者您也可以在调用开始动画之前尝试此操作。
这可能有效。
From my understanding android doesn't draw a portion of a view that is not visible on the screen. When apply animations to a view, only the pixels are shifted while the view remains in the old position which should be the problem as only the visible pixels of your image are only shifted.
My idea is to add a animation listener and overide the animationStart method and add the view manually to the corrent posistion or you can also try this before you call the start animation.
This might work.