tags:

views:

162

answers:

1

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

+1  A: 

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.

Dimitar Dimitrov