Scroll ListView smoothly and programmatically - android

I have searched a lot but I couldn't find an answer.
I want to implement something like in Go Launcher. When you drag an icon in app drawer and move it out of container top or bottom bound, the list begins to scroll.
So far, I have tried following things:
Dispatch touch events to simulate scrolling - impossible while touching the screen
Use smoothScrollBy() method - almost there, but it scrolls only screen height distance
Use scrollBy() - it moves only the container and leaves blank space. I would put there some rows if only I could be able to reuse views that went off the screen.
I need the ListView to scroll SMOOTHLY.
So here goes ma question. Anybody knows how can it be done? I'll put a gratitude in About section of my app to person who will help me:)

using listview and try scrollToPosition(),or smoothscrollBy()

Related

Center aligned selection with animation in ListView (?)

I need a component that works like the picture below but I'm having trouble coming up with some kind of decent solution that works.
I want the list to have a center locked selection but being scrollable with the d-pad. This is for an application running on a TV so no need for touch scroll. So when pressing down on the remote d-pad the list will scroll and a new item will size up and the current selected one will size down and the new selection will still be in the middle.
I've tried doing this using a ListView that I extended and programmatically scrolling when pressing down or up. On scroll finished I called notifyDatasetChanged() on the ListView for re-inflating of the childs and in the ListViews adapters getView() I made the animation of the view located at the current selected position.
This is not optimal since I need to call notifyDatasetChanged(), which re-inflates all visible views, for the animation to apply. The UI becomes laggy when doing this and scrolling fast. It's also not possible to make som kind of compress animation when current selected item goes out of selection. There is also some trouble with the end items (read views) such the first or last in the list when doing animation of them, the may sometimes go out of screen.
I think that his must have been done before and maybe I'm missing it when searching for an answer.
Have anyone done something similar or do you have some suggestions of how this can be achieved? Maybe I'm just starting of with the wrong component here..
Regards,
Kristoffer

Scrolling of list below another view

I have seen an app which has different type of scrolling. I hope images attached will be able to explain it. Here the list when scrolled up, moves up by taking DownloadAll, Playall button up too. Later on DownloadAll and PlayAll button stops going up and only the list scrolls up.
I don't know what this is called as. I tried searching, but could not find anything similar.
How can I achieve this type of scrolling?
Take a look at "Libraries for developers" it has a section of listview where you can find different styles of listviews (plus scrolling animations such as sticky, animated scrollview, flabby etc...)

Android - keeping a single element contained on screen

I'm experimenting to see if the layout scheme I want to use is possible. I want to have an XML layout that's scrollable. Within that scrollable layout, I want to have a single line going horizontally across the screen (I used just a View with a fixed height and different color). When that horizontal line reaches the top of the screen, and as I scroll down through the layout, I want it to stop and remain at the top of the screen while being able to scroll through everything below it.
I've been messing around in XML trying to get it to work, basically putting a bunch of junk before it and after it.
Any ideas as to how that might work? Would I have to do something fancy with the java code to fix the red line at the top when the scroll position reaches a certain point? Your help would be greatly appreciated.
I am assuming you want something like Gmail app where when you scroll a mail the header sticks on top... To do this, you need 2 views. You have your regular scroller below and overlay a fixed view on top (you can use a relative layout to do this). When your cell goes past a certain spot, you want to populate and set the visibility of the fixed view to VISIBLE. This would give the impression that the view you want to 'stick' to the top really just got stuck rather than scrolled out of view. You'll have to work out the opposite scrolling scenario too based on the location and height of the scrolled cell/view.
HTH

Vertical smooth scrolling of values in a text view

I have a text view where in i have to keep ages between 1-99. I also have two buttons ^ and v(i mean up and down arrows) on clicking them the values of the age should smoothly scroll to next or previous value.
I have been trying different ways but couldnt achieve smooth scrolling. Can anyone please give me any idea of how to achieve the task.
I think the easiest way is to simply put the TextView within a ScrollView, and let the arrows interact with the ScrollView, by using things like the fling method and playing around with the velocity parameter to suit your needs.
Use the animation framework.
When pressing down, start the 'down'-animation.
When pressing up, start the 'up'-animation.
Read more about animation here: http://developerlife.com/tutorials/?p=343
View animation is not much matured and hence i am noy sure if that can be used for moving the views.
Please find the description below:
Another disadvantage of the view
animation system is that it only
modified where the View was drawn, and
not the actual View itself. For
instance, if you animated a button to
move across the screen, the button
draws correctly, but the actual
location where you can click the
button does not change, so you have to
implement your own logic to handle
this.
Source
To scroll smoothly you can try using the scroller component.
Reference
What you would need to do is pass the duration of the scroll in the constructor and then use the property
setFinalY(int newY)
to increment the counter position by 1 unit (equal to the height of the item).
Please let me know if that helps!

Android: Detect when ScrollView has finished scrolling and bouncing back?

I have a ScrollView which has two hidden images, one at the top and one at the bottom. In between there is a bunch of visible content.
What I need to do is make these images hidden by default but when you scroll all the way up or all the way down you could see them as you're scrolling. But then as soon as you stop scrolling it should bounce back to the visible area so that the hidden images aren't showing.
Basically I'm trying to imitate the bounce scrolling feature of the iphone UIScrollView.
I have my ScrollView all setup and I do a scroll at the beginning so as to hide the top hidden image. Now all I need to do is detect when a scrolling has ended, figure out the Y position, and check whether a hidden image is shown. If it is, I would just programmatically scroll the view back so that the hidden image is hidden.
I hope all that made sense.
So anyways, I know how to programmatically scroll a ScrollView. Now what I need is some sort of callback to tell me when a ScrollView ended scrolling and also a way to get the ScrollView's current 'Y' position. Are there any such methods I could use?
I looked through the ScrollView docs but nothing jumped out at me. I'm still not very familiar with the Android naming schemes so maybe I missed something obvious somewhere.
Anyways, any help would be appreciated here. Cheers.
You can use an OnTouchListener to detect when the user presses/releases the list.
You can also use the onScrollStateChanged method of the OnScrollListener class (most likely in conjunction with a touch listener) to detect changes in the SCROLL_STATE - when the list has stopped scrolling the state will change from a state that is not SCROLL_STATE_IDLE to SCROLL_STATE_IDLE.
Alternatively if you are using 2.3 or above you can use an OverScroller to get the desired effect (see Modifying Android OverScroll for how to change the over scroll effect to an iPhone like one).

Categories

Resources