获取偏移量offsetX和offsetY后,可以通过以下几种方式移动DragView:
(1),通过layout实现DragView的移动。
layout(getLeft() + offsetX, getTop() + offsetY, getRight() + offsetX, getBottom() + offsetY);
(2),通过ViewGroup.MarginLayoutParams实现DragView的移动。
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) getLayoutParams()
mlp.leftMargin = getLeft() + offsetX
mlp.topMargin = getTop() + offsetY
setLayoutParams(mlp)
(3),通过offsetLeftAndRight和offsetTopAndBottom实现DragView的移动。
offsetLeftAndRight(offsetX);
offsetTopAndBottom(offsetY);
(4),通过scrollTo实现DragView的移动。
View parent = (View) getParent();
parent.scrollTo(parent.getScrollX() - offsetX, parent.getScrollY() - offsetY);
(5),通过scrollBy实现DragView的移动。
((View) getParent()).scrollBy(-offsetX, -offsetY);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)