编程翻译查看pre-蜂窝 [英] Programmatically Translate View Pre-Honeycomb

查看:158
本文介绍了编程翻译查看pre-蜂窝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式转换任意视图不使用动画( android.view.animation。* )?

How can I programmatically translate an arbitrary view without using an animation (android.view.animation.*)?

API 11推出 setTranslationX setTranslationY setX的 SETY getMatrix –所有这些都可以用来实现我在寻找什么。我似乎无法但是找上了之前的API级别等效。

API 11 introduced setTranslationX and setTranslationY, setX and setY, and getMatrix—all of which can be used to accomplish what I'm looking for. I cannot seem to find an equivalent on the prior API levels, however.

在其实施的 android.view.animation.TranslateAnimation 使用 getMatrix (早API 4)但它是在这段时间的私人API。

The android.view.animation.TranslateAnimation uses getMatrix in its implementation (as far back as API 4) but it was a private API throughout this time.

有没有办法做到这一点,而不诉诸反射?

Is there any way to accomplish this without resorting to reflection?

推荐答案

被收藏,因为我很乐意被证明是错误的这一个,但我做了一些拖丁基下降,调查时,一段时间回来碰到了类似的墙上。

Favorited because I would love to be proven wrong on this one, but I ran into a similar wall when doing some Drag-n-Drop investigations awhile back.

我是pretty的确保你坚持 offsetTopAndBottom() offsetLeftAndRight()的移动查看周围没有早期API的动画。这里最大的缺点是,这些方法实际修改上/下/左/右值,所以你必须,如果你想回去的地方,你开始做一些pretty的沉重的跟踪。

I'm pretty sure you're stuck with offsetTopAndBottom() and offsetLeftAndRight() for moving a View around without an animation in early APIs. The big downside here is that these methods actually modify the top/bottom/left/right values, so you have to do some pretty heavy tracking if you want to go back to where you started from.

另一种选择是简单地使用 TranslateAnimation 用很短的时间,并设置为 fillAfter ...

Another option would be to simply use a TranslateAnimation with a VERY short duration and set to fillAfter...

其他选项需要子类化,仍然无法pretty的,像翻译画布查看借鉴。这里的问题是,你还可以创建一个父不夹这是孩子们如此认为可以在其自己的边界之外画。

Other options require subclassing, and still aren't pretty, like translating the Canvas the View draws on. The problem here is you also have to create a parent that doesn't clip it's children so the view can draw outside its own bounds.

这篇关于编程翻译查看pre-蜂窝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆