如何在拖放时创建ImageView的副本?我在谷歌上搜索了,但没有找到任何结果。
请帮忙。
这里有一个完整的例子,看起来可以实现你想要做的大部分内容。唯一需要更改的是创建一个新的ImageView并将位图复制到其中。为了做到这一点,您需要修改MyDragListener类的onDrag()方法,使其类似于以下内容:
case DragEvent.ACTION_DROP:
// Dropped, reassign View to ViewGroup
View view = (View) event.getLocalState();
//ViewGroup owner = (ViewGroup) view.getParent(); // Removed
//owner.removeView(view); // Removed
LinearLayout container = (LinearLayout) v;
// Added the following to copy the old view's bitmap to a new ImageView:
ImageView oldView = (ImageView) view;
ImageView newView = new ImageView(getApplicationContext());
newView.setImageBitmap(((BitmapDrawable) oldView.getDrawable()).getBitmap());
container.addView(newView); // Changed to add new view instead
view.setVisibility(View.VISIBLE);
break;
当您单击特定图像时,动态创建一个ImageView,然后拖放动态创建的ImageView,这个想法怎么样?