移动一个View,可以调用以下的方法
view.offsetLeftAndRight(int)
// 左或右位移量,是相对当前View的坐标
view.offsetTopAndBottom(int)
// 上或下位移量
getScrollX()
// Return the scrolled left position of this view.
getScrollY()
getTop() // Top position of this view relative to its parent.
重画一个View,要用到mHandler的post方法,必须要在线程中重画。详细函数说明看android.os.Handler
view本身就是一个mHandler,可以直接调用post(Runnable),在Runnable中重画该View,view.getHandler()
可以取得该View对应的Handler。
如果要重画该View的父View,或可以用getRootView()取得最高层的父View,
mHandler.post( new Runnable() {
public void run() {
offsetLeftAndRight(2);
getRootView().invalidate();
}
});
例子:
class Test extends View implements Runnable {
public void run() {
getRootView().invalidate();
}
private void repaint() {
this.post(this);
}
}
android游戏个人经验2[转]
最新推荐文章于 2024-09-14 19:06:02 发布
posted by David Chen at May 07, 2009 7:29 PM