Android Question Drag and drop: z-index

Emme Developer

Well-Known Member
Licensed User
Hi to all!
I have a scroll view that has different panels inside. I want to enable the drag and drop to order the elements. To move the panel under dragged element, i get the view based on his top position. The problem is that after moving the panel, it's z-index doesn't change, so i'm not longer able to get another view because all z-order is the same. Any tips to achieve a right drag and drop tecnique to order the elements inside a scrollview? I hope clearly explained my issue. Thanks!
 

Emme Developer

Well-Known Member
Licensed User
I saw it, but i need to implement the solution by myself, without using another library

Did you try setting the Elevation of the panel moved (released)?
And BringToFront?
BringToFront of course can help, but after moving the panel i need an ordered z-order (first panel visible is the top, last panel is the bottom)
Elevation can't help me in this case
 
Upvote 0

LucaMs

Expert
Licensed User
A loop on panels, setting BringToFront?
A me sembra che funzioni. Non badare molto al metodo che ho usato per muovere i pannelli, cercato al volo e trovato quella classe DraggableView.
Ovviamente se serve puoi usare SendToBack invece di BringToFront.

It seems to me that it works. Do not pay much attention to the method I used to move the panels, I searched quickly and found that DraggableView class.
Obviously, if needed, you can use SendToBack instead of BringToFront, in the loop.
 

Attachments

  • MovePanels.zip
    10.2 KB · Views: 158
Upvote 0

Emme Developer

Well-Known Member
Licensed User
A me sembra che funzioni. Non badare molto al metodo che ho usato per muovere i pannelli, cercato al volo e trovato quella classe DraggableView.
Ovviamente se serve puoi usare SendToBack invece di BringToFront.

It seems to me that it works. Do not pay much attention to the method I used to move the panels, I searched quickly and found that DraggableView class.
Obviously, if needed, you can use SendToBack instead of BringToFront, in the loop.
Forse non mi sono spiegato bene. Il problema è che il movimento dovrebbe anche modificare lo z-order, in modo che il panel con label 1 spostandolo sotto porti il proprio z-index a 2. Usando un bring to front su tutti gli elementi, alla fine questi non vengono ordinati. L'algoritmo è abbastanza più complesso di quel che sembra, perché non hai il controllo diretto sullo z-index. Oltretutto la draggableview class modifica ulteriormente quest'ordine, perché aggiunge elementi all'activity

Maybe I did not say it clear enough. The problem is that the movement should also modify the z-order, so that the panel with label 1 moving it below brings its z-index to 2. Using a bring to front on all the elements, eventually these are not sorted. The algorithm is quite more complex than it seems, because you do not have direct control over the z-index. Moreover, the draggableview class further modifies this order, because it adds elements to the activity
 
Upvote 0

LucaMs

Expert
Licensed User
Forse non mi sono spiegato bene.
Maybe I did not say it clear enough.
Io ancora non ho capito bene.
I'm still don't understand what you want to achieve.

Oltretutto la draggableview class modifica ulteriormente quest'ordine, perché aggiunge elementi all'activity
Per questo motivo ti ho scritto di non fare caso al metodo che ho usato per muovere i pannelli, è stato il primo che ho trovato, non avevo voglia di "fare da me" :D
I used the first code I found to move the panels; I know that DraggableViews adds a transparent panel (this is why the code is a little "tangled" (routine pnl_Drop).

so that the panel with label 1 moving it below brings its z-index to 2
The example should work using SendToBack, then.
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Immagine.png


This is what i want to achieve. After moving the panel with drag and drop, if i use the code Activity.getview(1) i want to get panel D. Without editing the z-order, after moving the panel i will get panel B. A simple Bringtofront or SendToback is not enough
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
This is why a very good analysis must be done before starting to develop; and it is also the reason why I have not yet published my amazing app :p
Yes, a good analysis was done ... until the designer decided that drag and drop is needed just before beta release date
 
Upvote 0
Top