0
I made a Drag n Drop system, but when I insert the item, it seems that gravity is like top, when inserting new ones, they stand on top of each other, like drop where I drop the finger?
The items are in a Listview, I get them like this:
public void criarListagem(List<croquiA> cro) {
CroquiAdapter adapter = new CroquiAdapter(cro, this);
listView.setAdapter(adapter);
listView.setDivider(null);
listView.setOnItemLongClickListener((parent, view, position, id) -> {
arrayClass.p = arrayClass.pistasIds[position];
ClipData data = ClipData.newPlainText("simple_text", "text");
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(data, shadowBuilder, view, 0);
view.setVisibility(View.VISIBLE);
newClick(arrayClass.p, l);
if(l != 0){
findViewById(R.id.container).setOnDragListener(new MyOnDragListener());
}
return false;
});
Myondraglistener:
class MyOnDragListener implements View.OnDragListener{
public MyOnDragListener(){
super();
}
@Override
public boolean onDrag(View v, DragEvent event) {
int action = event.getAction();
switch (action){
case DragEvent.ACTION_DRAG_STARTED:
if(event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)){
return true;
}else{
return false;
}
case DragEvent.ACTION_DRAG_ENTERED:
break;
case DragEvent.ACTION_DRAG_LOCATION:
break;
case DragEvent.ACTION_DRAG_EXITED:
break;
case DragEvent.ACTION_DROP:
View view = (View) event.getLocalState();
RelativeLayout container = (RelativeLayout) v;
// Aqui eu copio a view e adiciono um ImageView
// em vez de remover, porque como é um adaptador, então é
// não é possível removê-lo
ImageView oldView = (ImageView) view;
ImageView newView = new ImageView(getApplicationContext());
newView.setImageBitmap(((BitmapDrawable) oldView.getDrawable()).getBitmap());
container.addView(newView);
break;
case DragEvent.ACTION_DRAG_ENDED:
break;
}
return true;
}
When I drop the items stay like this:
Notice that the images are piling up.
Whether there are two images or only one?
– ramaral
@ramaral I want that when I add, add a copy and this is created where I dropped the finger, like, I dropped it in the middle of the screen, the Imageview is created there, because the way it is, when I release it, they stay there at the top and they pile up :3
– Woton Sampaio
@ramaral and if possible, that this copy of the added image, it was also possible to drag n drop with it
– Woton Sampaio
You cannot use a Relativelayout. Use a Absolutelayout or a custom view. In the meantime look around, 'cause there might be something done.
– ramaral
@ramaral boy, I got it, but something ready nothing, I’ve already reviewed this whole Internet, I found nothing about
– Woton Sampaio
@ramaral ready :)
– Woton Sampaio