Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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中,如何在一个特定的水平布局中使用拖放在两个图像之间切换?_Android_Image_Drag And Drop - Fatal编程技术网

在Android中,如何在一个特定的水平布局中使用拖放在两个图像之间切换?

在Android中,如何在一个特定的水平布局中使用拖放在两个图像之间切换?,android,image,drag-and-drop,Android,Image,Drag And Drop,我想使用拖放功能在不同视图或不同布局的四个图像之间的任意两个图像之间切换 如果图像被放置到以水平线排列的特定B图像,则B图像将自动排列到A图像的位置 class MyDragListener implements OnDragListener { Drawable enterShape = getResources().getDrawable(R.drawable.shape_droptarget); Drawable normalShape = getResources().getDrawab

我想使用拖放功能在不同视图或不同布局的四个图像之间的任意两个图像之间切换

如果图像被放置到以水平线排列的特定B图像,则B图像将自动排列到A图像的位置

class MyDragListener implements OnDragListener {
Drawable enterShape = getResources().getDrawable(R.drawable.shape_droptarget);
Drawable normalShape = getResources().getDrawable(R.drawable.shape);

@Override
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:
    // Dropped, reassign View to ViewGroup
    View view = (View) event.getLocalState();
    ViewGroup owner = (ViewGroup) view.getParent();
    owner.removeView(view);
    LinearLayout container = (LinearLayout) v;
    container.addView(view);
    view.setVisibility(View.VISIBLE);
    break;
  case DragEvent.ACTION_DRAG_ENDED:
    v.setBackgroundDrawable(normalShape);
  default:
    break;
  }
  return true;
}

如果你能分享你的进度/代码或你遇到的任何问题,那就太好了。事实上,我找到了另一种使用视图的方法。但它不起作用…请给我一些想法。嘿,兄弟,我从过去15天以来就一直坚持执行类似于这种类型的要求…你能实现吗???请帮助我。请尝试公共布尔onTouch(视图、运动事件我)方法。。