How to enable dragging multiple ImageViews? - android

After I have added multiple ImageViews to a LinearLayout and implementing the onTouch event, the touch is enabled only for the last added ImageView and all the previous ImageViews don'. What is the possible solution ?
I have tried the code from the android developer blog:
http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html

Multi-touch in that example is designed for multi-touching a single View, not for touching multiple views at the same time.
This might help: Android firing onTouch event for multiple ImageViews
The solution you might be looking for, if you want to give the effect of multi-touching ImageViews, is placing another view on top of those views which allows you to capture all the touch events and pass the appropriate action to the view below it.
In my experience it has been much easier to use a SurfaceView and render the images to the view myself but this wouldn't be appropriate if there are other behaviours of View which you want to take advantage of.

Android Launcher app supports moveable views using the touch interface. The Launcher object model includes objects like DragLayer, DragSource, DragController, and DropTarget.
Using this concepts there is a nice tutorial for Moving Views In Android.
Look at that, I think its what you needed.

Related

Circular Buttons Group View

This is a snapshot from an app called "Noom Weight Loss Coach":
I was stunned by this circular view in this app. It can have some buttons (six in this snapshot but they can be more or less) and they can be rotated and have different colors.
I have a couple of questions:
Is there an existing library that provides this circular view?
If not, from where you would start if you want to build one? I am just interested in the circular look of the buttons. The rotation is not important.
I would recomend to use custom buttons. Derive your class from View, redefine onDraw() for drawing buttons state changes and listen for onTouch events.

Moving a view with a finger

I began to study Android not so long ago and have a question relating to which approach I should use to solve the simple task. Let's suppose I have a view (maybe, a button) and I want user to be able to move it across the screen with a finger. Until AbsoluteLayout was deprecated, the right approach seamed obvious. I would've just changed position of my view based on corresponding events. But what is right now?
Create a custom view of your own and add a onTouch event listener. It is very simple. Explained very well here.
If you're trying to move your views in order to navigate through your application or page through images in a gallery, Android provides a collection of widgets to do things like that. If you're trying to, say, pan across a large image, maybe this will help: Image in Canvas with touch events
Im using FrameLayout and update marginLeft and marginTop
You can add multiple children to frame layout, though this is not recommended because of multiple resolutions issues.
from the android docs:
FrameLayout is designed to block out an area on the screen to display
a single item. Generally, FrameLayout should be used to hold a single
child view, because it can be difficult to organize child views in a
way that's scalable to different screen sizes without the children
overlapping each other. You can, however, add multiple children to a
FrameLayout and control their position within the FrameLayout by
assigning gravity to each child, using the android:layout_gravity
attribute.
This "warning" is not applicable in your case because you are explicitly setting the margins according to the user touch event.

What is the best way to slide/switch between views ? (Custom Launcher)

I Build a Custom Launcher.
The launcher is made of views (each view will contain applications, images etc..)
The user can switch between those views in the home screen (almost like in every other laucncher)
the big difference is that in the launcher i build, when the user is in a specific view, he should be able to see the edges of the prev and/or the next view (if those are exist)
I tried to implement it by having a Horizontal Linear layout that holds the views.
It performs pretty nice, but not smooth enough.
I Concidered using viewflipper, but the problem with it, is that i can't see the prev and the next view.. (am i right?)
How should i implement this system?
thanks
Try to use ViewPager (android.support.v4.view.ViewPager). You need to download this .jar file to use it. http://developer.android.com/sdk/compatibility-library.html
Gallery already does this. It has issues with the smoothness and predictability of the left/right scrolling, but it will easily show your central view and the edges of the two neighboring views.

ViewFlipper caching issue

The views are not cached in a ViewFlipper. Is there a way wherein we can get an image of the view and show it to user so that he sees the Ui as we see on Home scrren(when we swipe the previous view also moves along and when we lift our finger, only then the next view is shown completely.)
What I want to do is that when the user starts moving his finegr on screen, the view should also move along(create an image of view).
I am not getting to do this, as when we swipe the present view goes and next view comes, we do not get both visible when we r moving our finger on screen.
Please if anyone gets what I am trying to do, do help me.
Thanks,
Farha
It's tricky to get scroll and swipe tracking working on Android, while using ViewAnimator or its subclasses.
They allow you to set in and out animations and start them at a given moment, but they work with discrete, either-this-or-the-other-view animations. They are actually using FrameLayout and after in or out animation is executed, other views' visibility is set to View.GONE to hide them from showing up under/over your current View.
The Launcher and the Gallery application are actually doing the functionality you want, by using a different approach.
They track the user touch input (onTouchEvent()), on MotionEvent.ACTION_MOVE they perform animations manually and on MotionEvent.ACTION_UP snap to the appropriate view, just like in the iPhone.
Unfortunately, this approach is actually more complicated than it looks like.
With the manual handling, you have to ensure that you are taking care of everything related to the touch input. This includes a lot of flag-raising, value-checking, event-delegating, etc.
If you want to get better acquainted with this, take a look at these classes from Gallery3D or Launcher's source code.
One other way to get nice horizontal scrolling is to use HorizontalScrollView.
You have to figure out a way to recycle your views, like you would with a ListView and you have to add the snap-to-view logic, but if you have to take care of a small number of views it could be the easiest approach.
Hope that helps.

Android "hover" event in custom layout

I have a custom layout that I have written that basically just displays a bunch of ImageViews. I am handing onTouch events for all the ImageViews in my layout.
However, if a user touches one imageView and then drags over another ImageView, I would like to be able to handle that as well.
How would I go about capturing this behaviour?
maybe this example is useful: http://www.anddev.org/viewtopic.php?p=11603
it relies on tracking the event with MotionEvent.ACTION_MOVE. the coordinates could be checked to determine when the element enters/exits a cell.
it uses drawview, but hopefully the same can be done w/imageview

Categories

Resources