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;
- OnDragListener no recibe DRAG_STARTED o DRAG_ENDED, pero obtiene ACTION_DROP
- Cómo cancelar View.OnDragListener en android durante la operación de arrastrar?
- ¿Cómo obtener el formato de fecha seleccionado por el usuario en Android?
- Android: realizar arrastrar y soltar mediante programación
- ¿Cómo se puede desplazar un "punto de destino" de Android drag-shadow de su "punto de contacto"?
- Cómo escribir un InputStream potencialmente enorme para el archivo?
- Hacer un lienzo transparente no transparente (tratando de sustituir el aspecto predeterminado de DragShadow con arrastrar y soltar en Android)
- Cómo obtener las coordenadas X, Y correctas de un DragEvent.ACTION_DROP
- Cómo reproducir el archivo de audio Mp3 desde el servidor
- Drag n drop textview en android
- Cómo arrastrar el TextView al destino correcto otro TextView
- Android: Problema de arrastrar y soltar
- Arrastrar y soltar sin eliminar del propietario
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