最后给出一小段代码用于在屏幕上拖动view(通过修改view的 layout ):
private float mDownX, mDownY, x, y; private int dx, dy, il, ir, it, ib; @Override public boolean onTouchEvent(MotionEvent event) { x = event.getX(); y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mDownX = event.getX(); mDownY = event.getY(); il = getLeft(); ir = getRight(); it = getTop(); ib = getBottom(); break; case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_UP: dx += Math.round(x - mDownX); dy += Math.round(y - mDownY); layout(il + dx, it + dy, ir + dx, ib + dy); break; } return true; }深入理解Android View 生命周期(3)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/ba9edd0d4565954249429a62ede79912.html