android GridView 拖拽Item及滚屏实现

针对以前修改的,进行了再修改。

这次就能很好的实现了长按,然后向下拖动,背景的Item也向上的效果。

注要对如下函数进行了修改:

private void onDrag(int x, int y) { if (dragImageView != null) { windowParams.alpha = 0.6f; windowParams.x = x - dragPointX + dragOffsetX; windowParams.y = y - dragPointY + dragOffsetY; // L.l("=================windowParams.y=====000========"+windowParams.y); windowManager.updateViewLayout(dragImageView, windowParams); } int tempScrollX = x - dragPointX + dragOffsetX; int tempScrollY = y - dragPointY + dragOffsetY; int rangeY = itemHeight; int maxHeight = getHeight() - rangeY; int position = pointToPosition(x, y); int gridViewCount = this.getCount(); int allContainCount = gridViewCount; int leftCount = gridViewCount % numColumns; if (leftCount != 0) { allContainCount += (numColumns - leftCount); } int upMaxPosition = allContainCount - numColumns; L.l("==========position:" + position + " max:" + upMaxPosition + " count:" + this.getChildCount() + " rangy:" + rangeY); // 如果position大于最大的item if (position >= upMaxPosition || position < numColumns) { L.l("=====last line=======postion:" + position); setEnabled(false); } else { L.l("=====good========tempScrollY: " + tempScrollY + " rangeY:" + rangeY + " maxHeight:" + maxHeight); if (tempScrollY < rangeY)// 假如漂浮的view已经进入第一行,则把当前的gridView滑出一个 { L.l("=====gridView scroll down=======:" + tempScrollY); setEnabled(true); int position2 = getFirstVisiblePosition(); smoothScrollToPosition(position2 - 1); // scrollTo(0, -itemHeight); } else if (tempScrollY > maxHeight) { L.l("=====gridView scroll up=======:" + tempScrollY); setEnabled(true); int position1 = getLastVisiblePosition(); smoothScrollToPosition(position1 + 1); // scrollTo(0, itemHeight); } } } 自此完全搞定Item拖拽。 下载代码链接: http://download.csdn.net/detail/synwith/4082316 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值