drag and drop imageview in android and detection position - android

I am making an application that drag and drop images. I need to make the user of the app can move an image from one point to another of the screen, for example He will touch the image and drag it to a point on the screen where there is another image, and when both images are superimposed, a message on screen, how could I do it?
Thanks very much

I think this can help you with the drag and drop
https://www.youtube.com/watch?v=H3qr1yK6u3M
To know image position you need to work with the ontouchevent:
How to get the Touch position in android?

Related

Android Studio - What are possible options to overlay two images and make only the right or left half of each image visible?

I am trying to have two images overlayed in two imageViews and when i start a swiping gesture the upper image is cropped vertically at the starting point of my touch gesture and the cropping line follows my gesture on screen to the left or right. When I move my finger to the right the cropping line should follow it and reveal more of the upper image for example, until I lift my finger from the screen. The crop should stay there then.
The goal ist to be able to compare two images with a swiping gesture.
I hope what I am trying to achieve is halfway understandable and I would be happy about any kind of input regarding that topic ;)
Thank you in advance

How to change Images in a custom photo gallary smoothly following the finger movement

I have a custom photo gallary app which shows images from a specific folder.
what is not clear to me is how to navigate between images smoothly following the finger movement, like this:
As seen by touching the display and moving to left, current image moves also corresponds to the finger movement and depending on where finger is up, current photo is stayed or replaced by the next photo (I hope image is clear enough!).
Could anybody please explain me how to make this effect?
I have tested ImageSwitcher but it is not how I want: in onTouch() method, I can detect the gesture (moving to left or right) and using a proper animation change images, but it is not possible to smoothly follow the finger movement.
Well, you might not want to try it because you have already done some work on your implementation, but :
The easiest way is to use a ViewPager that handles the scroll (and creates/deletes views when needed) and just override the default transformation with a PageTransformer.

android MotionEvent when finger enter or leaves view

I wan't to develop game named "Balda".
I have a 2d grid of imageviews (or buttons, maybe).
User should be able move his finger on the grid, and app should know wich images in grid was touched in this move.So, in the picture below is what I'm trying to achieve. A - is start point where user pressed on screen. B is end point where finger leaves the screen. And I need to know what images were touched (There are blue in the picture).
I know that I can do something like this. But I think that this is a wrong solution, because It contradicts the principle of giving functionality by responsibilitys.
I think that it is responsibility of the imageView to know when finger enters its borders and when it is leaving its borders.
I thought, that this would be in android API. And it has MotionEvent like EVENT_HOVER_ENTER and EVENT_HOVER_LEAVE but it's not working with finger. After finger is pressed on some View it will recieve all other MotionEvents, if I get it right.
I think that this is wrong. What can I do to get this functionality? Maybe I could create some custom listeners and custom Views, that supports them?
I think your requirement is slightly similar to custom gridview.
You can try below steps-
1)Create Custom view
2)Attach TouchListener to it.
3)Divide this view into 4*3 matrix.
4)Map your images to this 4*3 matrix
5)Write a function which gives the cell number respective toTouched Co-ordinates
6)After getting cell number;get the mapped image for that cell number
7)Put this image in arraylist
8)When user lifts his finger you will get arraylist of touched images(do whatever you want with it).
9)Remember to put this custom view in your activity
Tell me,if you have any doubt or concern

how can i use ontouch function to move an image with cursor in android?

I am making an small application in android in which i used an image and i used two buttons here when i click the first button the image will zoom and when i click second button the image will zoom out. But now i want when the image will zoom i can able to move the image with mouse cursor in emulator or(by touch in devise) so that i can able to view the whole image after zooming.can you suggest me any idea .**
Thanks in advance!
Try just moving the initial drawing coordinates. For instance when the image is first shown, I would imagine that it is at 0,0. when you want to move the image just directly modify the start coords accordingly.

Mimicking the "rubber band" effect from iOS in the Gallery on Android

I've got a Gallery class showing a bunch of images in an Android app, but since only one image is ever displayed at a time, it is difficult for the user to see when they have reached the first or last image in the gallery. Is there a way to mimic iOS' "rubber band" effect, so that the user sees a bit of empty space when dragging the last image, and they release it, the image snaps back to the center of the view. Is this possible to do?
Look into easing equations
http://www.gizma.com/easing/
when releasing the screen while been dragging the last image, you can use them to smoothly animate the image back to the center of the screen.
As for the effect while dragging the last image, use a multiplication factor on the position of the image so the more your finger reaches the side of the screen, the less the image will follow its movement.

Categories

Resources