如何在 Android 上将视图(例如图像)从一个面板复制到另一个面板?我试过:
case DragEvent.ACTION_DROP:
View view = (View) event.getLocalState();
LinearLayout container = (LinearLayout) v;
container.addView(view);
break;
但是,它不起作用。
这是 onDrag() 函数,我的应用程序退出Exception
:
public boolean onDrag(View v, DragEvent event) {
int action = event.getAction();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
// Do nothing
break;
case DragEvent.ACTION_DRAG_ENTERED:
v.setBackgroundDrawable(enterShape);
break;
case DragEvent.ACTION_DRAG_EXITED:
v.setBackgroundDrawable(normalShape);
break;
case DragEvent.ACTION_DROP:
// add view
View view = (View) event.getLocalState();
LinearLayout container = (LinearLayout) v;
container.addView(view);
break;
case DragEvent.ACTION_DRAG_ENDED:
v.setBackgroundDrawable(normalShape);
default:
break;
}
return true;
}