Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-拖放ImageView的副本_Android - Fatal编程技术网

Android-拖放ImageView的副本

Android-拖放ImageView的副本,android,Android,如何在Drad和Drop上创建ImageView的副本?我在谷歌上搜索过,但什么也没找到 请帮帮我。当您单击特定图像时,如何动态创建图像视图。然后拖放动态创建的图像视图,这是一个完整的示例,似乎可以完成大部分您想做的事情。看起来唯一需要的更改是创建一个新的ImageView并将位图复制到其中。为此,您需要将MyDragListener类的onDrag()方法更改为如下所示: case DragEvent.ACTION_DROP: // Dropped, reassign View to

如何在Drad和Drop上创建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;

java.lang.IllegalStateException:指定的子级已具有父级。您必须首先对孩子的家长调用removeView()。对此表示抱歉;我实际上没有尝试过,忘记了不能直接复制视图。您需要创建一个新视图,并将原始视图的位图复制到其中。我已经编辑了我的答案,这次我从那个站点构建了示例代码,并测试了我的更改。