TListBox scrolling effect

How can I implement an effective scrolling effect like this (mouse drag scrolling) in a list using a standard component TListBox

in Delphi XE2 FireMonkey?

+3


source to share


1 answer


One such solution might be to use TListBox.ChildrenCount-1

and check if it is smaller Position.Y

TListBox.Parent.Height + TListBoxItem.height

. Also, create a global variable boolean

such as "MouseIsDown".

Since every item inside the TListBox is actually a child object that you can work with and modify directly, just create a big empty one TListBoxItem

and make sure it is set as the last object in the list.

The OnMouseDown

set MouseIsDown

in to True, and OnMouseUp

set it to false.

Add TFloatAnimation

to TListBox with interpolation property set to itElastic

, or itBounce

. If MouseIsDown

set to false, disable this effect, and when MouseIsDown

set to true, enable the effect. You will need to do some work before resetting the list position to the last valid object. Perhaps do this in an event of OnFinish

the animation itself.

It would be more appropriate to calculate the position of this last object and set the StopValue

animation to that value.




Essentially you need to check if the coordinates of the final valid object (i.e. not a large empty object) in the list match the height of the list. If they do, and the mouse isn't turned off, the animation will be on and the scrolling will bounce. If they match and the mouse doesn't work, the animation is disabled and as such OnFinish

won't even be fired, and therefore the scrolling won't reset its position.

You will probably need to do an iterative nested procedure to check that each value is true.

It won't be as smooth as the iOS implementation, but it should give you something to work with.

0


source







All Articles