Android 拖动View View跟随手指一动

/**
* 拖动View 配合onTouchListener使用
* 设置View的布局属性,使得view随着手指移动 注意:view所在的布局必须使用RelativeLayout 而且不得设置居中等样式
*
* @param view
* @param rawY
*/
private void moveViewWithFinger(View view, float rawY ,int statusBar) {
if (rawY> view.getHeight()){
rawY = view.getHeight() + statusBar;
}
int left = 0;
int top = (int) rawY - mProfile.getHeight();
int width = view.getWidth();
int height = top + view.getHeight();
view.layout(left, top, width, height);
}
posted @ 2016-12-05 13:37  TeddyYan  阅读(3863)  评论(0编辑  收藏  举报