4

Anybody that knows how to make my own scrolling function like fling() or smoothScrollTo()? I have a class that is ScrollView extended but I cant find out how to make this...

I want it to work like fling but backwards, with that I mean instead of slowing down from a given velocity I want it to accelerate from 0 in the same rate as it slows down on fling and then stop scrolling at a given position...

the effect Im aiming at is like the WP7 lockscreen, you throw it off the screen upward, if your scrollview havent scrolled all the way to the end I want it to "fall down" and there for I want it to start at velocity 0 and increase until it hits the start position again.

Anybody that could help me or just point me in the right direction?

Alioooop
  • 465
  • 5
  • 12

2 Answers2

3

You might be able to get the effect you are looking for by setting a different Interpolator on the scroller.

For instance, you could try using an AccelerateInterpolator.

ie

Scroller myScroller = new Scroller(context, new AccelerateInterpolator());

EDIT: Be sure to read bigstones answer though, as my suggestion doesn't help unless you are willing to create your own ScrollView (which isn't all that hard since you have the source).

slund
  • 6,367
  • 2
  • 26
  • 19
  • 1
    +1 for pointing out about interpolators in the constructor. I didn't remember that! – bigstones Mar 16 '11 at 14:49
  • I tried making a own scrollview with the source code but its still some variables and other things that I cant use from my app... – Alioooop Mar 16 '11 at 21:34
  • the effect Im aiming at is like the WP7 lockscreen, you throw it off the screen upward, if your scrollview havent scrolled all the way to the end I want it to "fall down" and there for I want it to start at velocity 0 and increase until it hits the start position again :) – Alioooop Mar 16 '11 at 21:52
1

ScrollView uses a Scroller to determine how the fling animation goes. I think you can write a custom Scroller and change the function that determines the motion.

Here an example on using Scroller and here Scroller's source code.

Sadly, I don't know of a simpler way to have a ScrollView use your Scroller other than getting ScrollView's source and replacing standard Scroller with yours. The alternative is creating a simpler custom scrolling view.

EDIT

It seems like Android's notification bar effect. If you don't need it to follow the finger, but only respond to fling gestures, it shouldn't be too hard to achieve using animations and GestureDetector. Something like:

touch or slow fling -> bounce back animation;

fast enough fling -> slide up animation;

If you'd rather like it to follow your finger (like Android's notification bar), you would have to play with View's scrolling framework and I think it's going to be more complicated (yet you could go and look how they made it).

Community
  • 1
  • 1
bigstones
  • 15,087
  • 7
  • 65
  • 82
  • Its the way I made it for now but in that way I cant stop the animation in the middle when I press and hold the scrollview while its animating.... – Alioooop Mar 19 '11 at 18:47
  • @Alioooop then you could try the second option. well... good luck! – bigstones Mar 19 '11 at 19:01