Android自定义缩放动画性能不佳
我有一个具体的问题,但希望有人能插话并提供帮助。
我编写了一个自定义缩放动画(发布可在一定时间之间将目标视图更改为处理程序的可运行对象),但是当我更改视图的宽度和高度时,就好像我在 (0,0) 附近执行了缩放视图的中心,而我想围绕其中心进行缩放,因此我通过相应地更改其边距来移动视图。问题是,当缩放迭代步长太小时(即 0.01f 及以下)时,我必须将视图的边距更改为 1px 之类的值,有时仅在其中一个方向上更改,这使得动画看起来好像有问题。我不确定确切的原因,但我尝试了以下操作:
1)我尝试通过覆盖父视图的 onLayout() 来更改边距,该父视图将在缩放时设置布局参数时进行调用(我是按顺序这样做的为了避免在移动时再次调用 setLayoutParams() ,实际上现在看起来不太合理,因为 setLayoutParams() 只是设置了一些稍后将使用的标志)。
2)我正在检查要设置的新边距,以便仅当新旧边距在 X 和 Y 方向上存在差异时才设置它们。
3)我尝试使用 view.offsetLeftAndRight() view.offsetTopAndBottom() 而不是更改布局参数来移动视图,但再次无济于事。
有什么建议可以解决这个问题吗?
I have a bit specific problem, but hopefully someone will chime in and help.
I've written a custom zoom animation (posting runnables that change the target view to a handler between certain amount of time) but when i change the view's width and height it is as if I've performed a zoom around (0,0) of the view whereas I want to zoom around its center so I move the view by changing its margins accordingly. The thing is though that when the zoom iteration step is too small (i.e 0.01f and less) I have to change the margins of the view by something like 1px sometimes only in one of the directions which makes it look as if the animation is glitchy. I'm not sure of the exact reason but I've tried the following things:
1) I tried changing the margins by overriding onLayout() of my parent view which will be caled when setting the layoutParams upon zooming( I did this in order to avoid a second call to setLayoutParams() upon moving which actually now doesn't seem quite reasonable since setLayoutParams() just sets some flag which will be used later on).
2) I'm checking the new margins to set so that they are set only when there's a difference between the new and the old margins in both X and Y directions.
3)I tried using view.offsetLeftAndRight() view.offsetTopAndBottom() instead of changing the layout params in order to move the view, but it was again to no avail.
Any suggestions what will do the trick?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确,您需要从视图中获取位图缓存并手动绘制它。在这种情况下,将无故障地绘制位图(如果位图过滤打开)。
您可以按照以下步骤进行操作:
可能可以通过Android动画类来完成,但我不使用它,因为它非常有限。
If I undestand you correctly you need to get Bitmap cache from view and draw it manually. In this case bitmap will be drawn without glitches (if Bitmap filtering is on).
You can do it in following steps:
Possibly it can be done via Android Animation class but I do not use it as it quite limited.