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 8977741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:26:30+00:00 2026-06-15T19:26:30+00:00

I am trying to allow the user to drag and drop and image from

  • 0

I am trying to allow the user to drag and drop and image from on position to another. The screen layout is as follows:

1 2 3

4 5 6

7 8 9

I want the user to grab image 2, 4, 6, or 8 and drag it to image 5. Upon dragging to image 5 I want to load up a fragment. The user can only drag the image in a straight line from it’s current position to 5’s position. ie image 2 and only drag down and only until it is overtop of image 5, image 4 can only drag right until overtop of 5, etc.

Any insight on how to do this is greatly appreciated.

Thanks,
DMan

  • 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-15T19:26:32+00:00Added an answer on June 15, 2026 at 7:26 pm

    So I figured out a way to get it to work. Pretty hacky but I basically use the image positions and transition it via a margin in the direct that I want from it’s center until it reaches the desired position.

    I created a temp image (mTempImage) and hide my main image because the image had parameters set in the layout that forced it to stay above a specific item in the layout and wouldnt let it margin less than that items height.

    Here is a sample from my onTouchListener

    int eventX = (int)event.getX();
                        int eventY = (int)event.getY();
    
                        int movingViewHeight = view.getHeight();
                        int movingViewWidth = view.getWidth();
    
                        int destinationTileTop = mTileHere.getTop();
                        int destinationTileLeft = mTileHere.getLeft();
    
                        // Transparent 'Tile Here' image (1)
                        // Transitional 'Tile Here' image (0 - 1)
                        // Opaque 'Tile Here' image (0)
                        float alphaMultiplier = 0;
    
                        switch(view.getId()) {
                        case R.id.item_position_2:  
                            // Only allow sliding down from center of object (positive eventY)
                            if (eventY > movingViewHeight / 2) {
                                // Calculate the amount that the image has moved from it's center point
                                int posFromImgCenter = (eventY - movingViewHeight / 2);
                                // Check if the image has reached the center point and stop it's motion any farther
                                if (posFromImgCenter >= destinationTileTop) {
                                    params.setMargins(view.getLeft(), destinationTileTop, 0, 0);
                                    alphaMultiplier = 1;
                                }
                                // Slide the image with the positioning of the persons finger
                                else {
                                    params.setMargins(view.getLeft(), posFromImgCenter, 0, 0);
                                    alphaMultiplier = ((float)posFromImgCenter / (float)destinationTileTop);
                                }
    
                            }
                            // Attempting to slide in an invalid direction leave the image where it is
                            else 
                                params.setMargins(view.getLeft(), view.getTop(), 0, 0);
    
    ... MORE CODE HERE FOR OTHER ITEM POSITIONS
    
    // AFTER SWITCH STATEMENT COMPLETE UPDATE VIEW ITEMS ACCORDINGLY
    
    // default 0 if not set with valid movement
                        mTileHere.setAlpha((int)(255 - (255 * alphaMultiplier)));
                        mTempImage.setLayoutParams(params);
                        mTempImage.invalidate();
    

    Thanks,
    DMan

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

Sidebar

Related Questions

I am trying to allow a user to select an image, either from the
I want to allow user to drag and drop UI elements. I've 'container' and
I want to allow dropping of image files in my application: Users can Drag
I'm trying to use the following to allow a user to drag photos onto
I'm trying to allow the user to select a contact from the People app
So I'm trying to add some ability to my project to allow user-defined properties
I trying to pomp showPermissionDialog for allow the user to post something in a
I am trying to set up a page that will allow the user to
I'm trying to modifty the Flex Tree control to allow a user to select
i'm trying to add some navigation arrows which allow the user to go to

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.