I am looking for an optimized way of implementing Pinch Zoom feature on my GirdView containing images. Why optimized? Because playing with Bitmaps any day gifts me with Out of Memory exception. Till date I have implemented the handling of Multitouch on screen by using switch (event.getAction() & MotionEvent.ACTION_MASK)
in my onTouch event and getting to the case of "MotionEvent.ACTION_MOVE".
Further I have been rebuilding the grid by calling the Adapter again and again on every case of pinch zoom in or out but one or the other moment I get out of memory exception.
Also I have tracked the intensity of pinch by taking the difference of coordinates between the old touch point and new touch point (using the trigonometry formulae: [(x2-x1)^2 +(y2-y2)^2]^1/2 ).
To summarize I am looking for help/suggestions on two points:
1) The way I have been tracking the intensity of Pinch Zoom in/out, is this a correct way?
2) What will be an optimized way of rebuilding the grid after the detection of pinch zoom in/out.
Thanks.
Extend the grid view and make your own class, make a custom grid view and set the gesturelistener in that gridview and it will work out(if u need it in version > android 2.1) , i think...!!!!!!
Related
I need to build a screen with map of a theater, and user can interact with zoom in/out and choose seats on map.
When user touch on a seat, the icon of seat is changed.
Is there some lib/component to build my own map with touch areas? Or some good idea to use Android API to solve this problem?
Thanks.
You should take a look at the SurfaceView API.
It provides you with an easy to use abstraction for drawing on a canvas. You can use it to render your theater image and intercept touch events on it. However, zoom in and zoom out are not supported out of the box, so you should implement them separately.
Another thing you can do is show your image in an ImageView and use scaling to implement the zoom in/zoom out, but then intercepting the exact touch position can get a little tricky.
I am currently trying to figure out which way is best to display a picture in an Android app. The picture will be a map and will be a big picture (3000x3000 pixels). I would like to add the ability to pinch zoom into the picture and move the image around the screen but not have the scale of the image changed. I have played around with a lot of solutions that when the image is moved it is auto re-sized. Is there a way of doing this? Thanks.
However I have used many libraries for loading large images but subsampling-scale-image-view is the best library I found and also it supports a variety of gesture support.
Gesture detection
One finger pan
Two finger pinch to zoom
Pan while zooming
Seamless switch between pan and zoom
Fling momentum after panning
Double tap to zoom in and out
Options to disable pan and/or zoom gestures
Supports interception of events using GestureDetector and OnTouchListener
Extend to add your own gestures
Njoy!
i am trying to write an Application for android that zooms in AFTER the user FINISHED dragging or touching the screen (this means at motionEvent.ACTION_UP).
i want it to be continuous just like in a pinch zoom, but the problem is that pinch zooming is a continuous action and therefore create many events , what i am looking for is a SINGLE event (motionEvent.Action_up) that will cause continuous zooming.
Thanks in advance.
After MotionEvent.ACTION_UP you should set a timer which will repeatedly, and slowly, zoom over the designated area you decide (Instead of zooming according to future motion events, like in pinch zooming).
I want to create some kind of a tower defense map using a background image which is fourth as large as the screen of the device (twice horizontal, twice vertical).
my question is, how can I do this best. I'm new to Android, just got some Java basics , and want ti try out some stuff.
I want the user to scroll over the entire map using their finger and want him to zoom in via 2 finger pinch, and of course the objects (towers, sprites) should stay were they are.
I've been searching for hours for now and only found answers like " use Scrollview". I just want a food for thought to get in the right way, maybe with some examples.
You can use ImageView and set appropriate onTouchListener where you will detect pinch-to-zoom gesture using GestureDetector and change view coordinates when user drags the finger.
I need apply pinch and zoom gestures for my complete view.
In my view there are a lot of controls like textviews, buttons, list view and all. This all have different listeners. I need to apply zoom to this without affecting the my UI controls and listeners.
I know how to zoom a image and using a webview. But how we apply zoom to complete layout with different controls and listeners ?
(I'm working on honeycomb)
At last i got the solution. We can use setScalaX and setScaleY with pivot point
I have explained it here
Zooming a view completely
Pinch Zoom to view completely
Im not aware of anything that will simply take care of this. All I can say is that I've known others to achieve this by applying a translation matrix to a route view group which then applies to it's children's views (if I remember correctly).
From this the touch events were converted to apply to the translated view.
To handle the pinch to zoom this may be of use: Android Dev - OnScaleGestureListener