Cómo arrastrar varias vistas de botón en java

Tengo una aplicación donde necesito mover pilas de botones (al igual que mover parte de una pila de cartas de una pila a otra). He definido todos los botones en un diseño xml y configuración de toque y arrastrar a los oyentes para todos. Puedo arrastrar y soltar cualquier botón alrededor de la pantalla individualmente. Pero lo que necesito hacer en algunos casos es arrastrar los otros botones apilados en la parte superior del botón original que hice clic al mismo tiempo. ¿Hay una manera de "engañar" o simular que se presiona otro botón (por lo que el oyente lo registra)? Gracias *** Editado 9/8/15 @Override public boolean onTouch (Ver v, MotionEvent e) {// tosty ("mclicking:" + mClicking); Int startpos = 0; Switch (e.getAction () y MotionEvent.ACTION_MASK) {

case MotionEvent.ACTION_DOWN: isWastePile=false; get_selected_deck(v); // determines which of 7 decks or layouts in the tablau you have // clicked FromDeck = selecteddeck; FromDeckCard = deckcard; FromDeckButton = deckbutton; // if (!mClicking) { mClicking = true; //String piecetag = (String) v.getTag(); // // IDEA!!!/ /// /* * I wrote a function that finds all the ImageButtons below where * the user clicked, and set them all to invisible. I then created a * new Linear Layout within the Linear Layout that the user clicked (during the ACTION_DOWN event), * and passed that into the Drag Shadow builder during the ACTION_MOVE event. * * Once into the ACTION_DROP portion, I simply referenced global * variables to figure out if the user dropped in one or multiple * ImageButtons, and dealt with them accordingly. */ //if (!isWastePile) { //draglayout.setClipChildren(false); lltemp = new LinearLayout(this); lltemp.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams llparams = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); llparams.setMargins(0, -52, 0, 0); lltemp.setLayoutParams(llparams); draglayout.addView(lltemp); for (int i = 0; i < deckstack_list[selecteddeck].size(); i++) { if (v == (draglayout.getChildAt(i))) { startpos = i; for (int o = i; o < deckstack_list[selecteddeck].size(); o++) { // layout5.removeViewAt(o); draglayout.getChildAt(o).setVisibility(View.GONE); // all // buttons // being dragtempstack.push((Integer) deckstack_list[selecteddeck].get(o)) ; // dragged // to // invisible // then recreate another linear layout within layout5 // and pass to dragshadow builder // to do // also set a GLOBAL variable with stack count (number // of cards dragged) lltemp.setClipChildren(false); lltemp.addView(createtempButtons(o, startpos)); } } } //} // end if wastepile check statement //tosty("dragtempstack size: "+dragtempstack.size()); break; case MotionEvent.ACTION_MOVE: //tosty("Action MOVE"); Log.i("ACTION Event: ", "ACTION MOVE"); // v = layout5; v = lltemp; v.setVisibility(View.INVISIBLE); v.bringToFront(); v.invalidate(); v.setVisibility(View.VISIBLE); //DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v); DeckDragShadow shadowBuilder = new DeckDragShadow(v); v.startDrag(null, shadowBuilder, v, 0); correctDrag = false; break; private Button createtempButtons(final int i, final int startpos) { final Button b = new Button(this); b.setOnTouchListener(this); b.setOnDragListener(new DeckDragListener()); b.setBackgroundResource(cardimagearray[dragdeckstack.get(i)]); float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 45, getResources().getDisplayMetrics()); float height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 61, getResources().getDisplayMetrics()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( (int) width, (int) height); float margTop = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, -36, getResources().getDisplayMetrics()); if (i > startpos) { params.setMargins(0, -57, 0, 0); } b.setLayoutParams(params); // b.bringToFront(); // b.invalidate(); b.setVisibility(View.VISIBLE); return b; 

En lugar de intentar replicar a los oyentes para cada botón, consideraría los botones como grupos. Cuando hace clic en un botón dentro de un grupo, se divide en dos grupos: el botón con los botones por encima y lo que está dejando atrás. A continuación, el grupo se arrastra y deja caer sobre otros grupos.

Los grupos podrían ser LinearLayouts como sugiere Templerschaf:

  • Haces clic en LinearLayout
  • Registra qué elemento
  • Hace un LinearLayout nuevo que contiene los elementos debajo de ese elemento en la posición correcta
  • Elimina los elementos debajo del elemento que se ha hecho clic y los redimensiona en consecuencia.
  • Entonces el diseño puede continuar siendo arrastrado
  • A continuación, se puede descartar en otro LinearLayout, que agregará los elementos a su propia lista

Esto es muy parecido a las animaciones ListView. Ver:

https://www.youtube.com/watch?v=_BZIvjMgH-Q

https://www.youtube.com/watch?v=mwE61B56pVQ

https://github.com/bauerca/drag-sort-listview/blob/master/library/src/com/mobeta/android/dslv/DragSortListView.java

  • ¿Cómo obtener el comportamiento de pantalla de inicio de arrastrar a bin, en mi propia aplicación?
  • ¿Cómo obtener la vista mientras arrastrar y soltar en android?
  • Cómo hacer Drag & Drop Button en Android
  • ¿Cómo transformar currentTimeMillis a un formato de fecha legible?
  • ¿Cómo restringir el arrastrar y soltar a lo largo del eje y sólo en android?
  • Leer WCF REST fecha de android
  • Arrastrar y soltar con onDraglistener animar para volver a la posición original si no se deja caer en el objetivo
  • Cómo convertir la ubicación de toque de View en la ubicación de la pantalla HTML de WebView
  • Establecer anclaje personalizado al arrastrar una vista
  • Android - Restringir arrastrar y soltar a un cuadro delimitador
  • ¿Por qué estoy recibiendo este error "recurso esperado de tipo raw" en Android Studio?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.