Android gridview drag and drop item and scrolling implementation

Source: Internet
Author: User
For the previous modification, the modification was made.

This time we can achieve a good long press, and then drag down, the background of the item is also up the effect.

Note that the following functions must be modified:

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 = getheig HT ()-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); // if the position is greater than the maximum itemif (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) // If the floating view has entered the first line, then the current gridview is slid out of a {L. L ("===== gridview scroll down =======:" + tempscrolly); setenabled (true); int position2 = getfirstvisibleposition (); smoothscrolltoposition (position2-1); // scrollto (0,-itemheight);} elseif (tempscrolly> maxheight) {L. L ("===== gridview scroll up =====:" + tempscrolly); Set Enabled (true); int position1 = getlastvisibleposition (); smoothscrolltoposition (position1 + 1); // scrollto (0, itemheight) ;}} this is all about item dragging. Download Code link: http://download.csdn.net/detail/synwith/4082316

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.