android - Drag and drop in ScrollView -


i have imageviews inside horizontalscrollview.

i able drag , drop imageviews somewhere else, still maintain scrolling capability. dragging should activated when user starts vertical motion finger.

for now, have drag , drop activate on long-press, not solution.

to illustrate: drag , drop

i had well. after reading http://techin-android.blogspot.in/2011/11/swipe-event-in-android-scrollview.html adapted code follows:

class myontouchlistener implements view.ontouchlistener {     static final int min_distance_y = 40;      private float downy, upy;      @override     public boolean ontouch(view view, motionevent event) {         switch (event.getaction()) {             case motionevent.action_down: {                 downy = event.gety();                 return true;             }             case motionevent.action_move: {                 upy = event.gety();                  float deltay = downy - upy;                  // swipe vertical?                 if (math.abs(deltay) > min_distance_y) {                     if (deltay < 0) {                         //start drag here if appropriate                         return true;                     }                     if (deltay > 0) {                         //or start drag here if appropriate                         return true;                     }                 }             }         }         return false;     } } 

and set listener on imageviews:

            imageview.setontouchlistener(new myontouchlistener()); 

in version of code checking movement in vertical direction (i changed minimum movement 40 instead of 100 in original code). if vertical movement detected, specific imageview can begin drag or other actions want. if vertical movement not detected, imageview's mytouchlistener returns false means imageview not consume touch event. allows parent scrollview touch event , consume (for scroll detection). answers here helpful understanding touch events: motionevent handling in scrollview in android.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -