hi i am new in android i use the android 2.2 api level-8.so i can use two image one for drag purpose and another for Drop purpose.
Here i Display some my code which i can do here.
Code Is which Display Device Height width and ball is my drag Image View.
windowwidth = getWindowManager().getDefaultDisplay().getWidth();
windowheight = getWindowManager().getDefaultDisplay().getHeight();
Log.e("Screen Width-->", "" + windowwidth);
Log.e("Screen Height-->", "" + windowheight);
ball = (ImageView) findViewById(R.id.secondImage);
tempAnimationDrawable = (AnimationDrawable) ball.getDrawable();
ball.setOnTouchListener(this);
Apply seton touch Listener on this.
the on touchListener is below.
public boolean onTouch(View v, MotionEvent event)
{
layoutParams = (RelativeLayout.LayoutParams) ball.getLayoutParams();
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
int imgWidth = ball.getWidth();
Log.e("Image Width -->", "" + imgWidth);
int imgHeight = ball.getHeight();
Log.e("Image Height -->", "" + imgHeight);
int x_cord = (int) event.getRawX();
System.err.println("Display X code->" + x_cord);
int y_cord = (int) event.getRawY();
System.err.println("Display y code->" + y_cord);
int getX=(int) event.getX();
System.err.println("Display Here X Value -->"+getX);
int getY=(int) event.getY();
System.err.println("Display Here Y Value -->"+getY);
if (x_cord < windowwidth && getX < imgWidth )
{
x_cord = windowwidth;
Log.e("If Part X Cord-->", "" + x_cord);
}
if (y_cord > windowheight)
{
y_cord = windowheight;
Log.e("If Part Y Cord-->", "" + y_cord);
}
layoutParams.setMargins(imgWidth + incLeft, imgHeight + incTop, imgWidth + incRight, imgHeight + incBottom);
// layoutParams.setMargins(left, top, right, bottom)
ball.setLayoutParams(layoutParams);
break;
default:
break;
}
return true;
}
now i what to do.
Hi i give you whole code of drag and drop in android 2.2 without use the surfaceview.
i give the link here.
go there and see the code and implement this.
iam sure it will be helpful to you.
link is
How to implement Drag and Drop in android 2.2?
And Another is
http://code.google.com/p/android-drag-and-drop-basic/source/browse/src/edu/sbcc/cs123/draganddropbasic/DragAndDropBasicActivity.java