Faites glisser et déposer des images dans android

Je travaille sur un word scramble jeu qui permet à l'utilisateur de déplacer l'image à l'image..si l'image ne correspond pas alors il doit revenir à sa position initiale, d'où il a été tiré.J'ai écrit un exemple de code pour déplacer l'image, mais le problème, c'est que si je déplace une image de l'image voisine aussi commence à se déplacer.. Voici un exemple de code.

 /** Touchmoveimage.java*/
package com.examples.Touchmoveimage;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
public class Touchmoveimage extends Activity implements OnTouchListener{
int windowwidth;
int windowheight;
private LayoutParams layoutParams ;
private LayoutParams layoutParams1 ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
windowwidth = getWindowManager().getDefaultDisplay().getWidth();
windowheight = getWindowManager().getDefaultDisplay().getHeight();
ImageView ball= (ImageView)findViewById(R.id.ball);
ball.setOnTouchListener(this);
ImageView ball1 = (ImageView)findViewById(R.id.ball1);
ball1.setOnTouchListener(this); 
}   
public boolean onTouch(View v,MotionEvent event) {
switch(v.getId())
{
case R.id.ball:
ImageView ball= (ImageView)findViewById(R.id.ball);
layoutParams = (LayoutParams) ball.getLayoutParams();
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:   
break;
case MotionEvent.ACTION_MOVE:
int x_cord = (int)event.getRawX();
int y_cord = (int)event.getRawY();
if(x_cord>windowwidth){x_cord=windowwidth;}
if(y_cord>windowheight){y_cord=windowheight;}
layoutParams.leftMargin = x_cord -25;
layoutParams.topMargin = y_cord - 75;
ball.setLayoutParams(layoutParams);
break;
default : break;
}
case R.id.ball1:
ImageView ball1= (ImageView)findViewById(R.id.ball1);
layoutParams1 = (LayoutParams) ball1.getLayoutParams();
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:   
break;
case MotionEvent.ACTION_MOVE:
int x_cord = (int)event.getRawX();
int y_cord = (int)event.getRawY();
if(x_cord>windowwidth){x_cord=windowwidth;}
if(y_cord>windowheight){y_cord=windowheight;}
layoutParams1.leftMargin = x_cord -25;
layoutParams1.topMargin = y_cord - 75;
ball1.setLayoutParams(layoutParams1);
break;          
default : break;
}
}
return true;}
}
     <!-- main.xml -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView 
android:layout_width="50sp" 
android:layout_height="50sp" 
android:id="@+id/ball"
android:src="@drawable/ball">
</ImageView>
<ImageView 
android:layout_y="30dip" 
android:layout_x="118dip" 
android:layout_width="50sp" 
android:layout_height="50sp" 
android:id="@+id/ball1"
android:src="@drawable/ball1">
</ImageView>
</LinearLayout>

Quelqu'un m'aider plz..à Essayer toutes les choses possibles pour le résoudre..

Bonjour Pinky Votre Problème est Résolu ou pas?
tech-papers.org/android-drag-and-drop
Voir: developer.android.com/guide/topics/ui/...

OriginalL'auteur Veena | 2010-12-24