Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8325103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:19:14+00:00 2026-06-09T00:19:14+00:00

hi i am new in android i use the android 2.2 api level-8.so i

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:19:16+00:00Added an answer on June 9, 2026 at 12:19 am

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From the official documentation: A subclass of Dialog that can display one, two or
I'm new to Android development and I wonder if I can use some Java
I can successfully connect through Bluetooth my Nexus One Android Phone to another Bluetooth
I am a new android app developer and i want to use google map
i am new to android development. I am use the following code to set
i am new in android.i make a simple maths apps. i use the check
I am relatively new to Android, but I am looking to use an interactive
I see that as of API Level 8, you can request a handle to
I am using the Android Compatibility Package with API Level 10. I have a
I'm working on an Android project (API level 10) which needs to send and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.