layout - How to save the position of a dragged ImageView in Android? -
following situation:
i have layout imageview
s on it. user can drag them around. have button add new imageview
s. when clicking overview can choose image. overview activity ends , return fragment.
now problem:
because fragment
initialized again when returning other activity, positions of imageview
s put in place before lost.
whats best way save positions of dragged imageview
s? margins of each , save them? have sqlite db running think it's overkill save position of each imageview
there.
well question app remember positions in case of restart?
if do, need use sort of persistent storage, such database, file
or sharedpreferences
.
if not, cache them in memory, in hashmap
example.
to positions, in ondraglistener
:
public boolean ondrag(view v, dragevent event) { final int action = event.getaction(); switch(action) { // ... case dragevent.action_drop: float x = event.getx; float y = event.gety; saveposition(x, y); break; } }
Comments
Post a Comment