Reputation: 5455
I made a ViewFlipper
that navigates between articles of news I parse from the web.
It all works, but when I scroll down in the current item and then navigate to the next/previous item the ScrollView
doesn't scroll to the top of the new article item. It just 'hangs' in the place where i ended reading my last item.
At the end of my onClick(View v)
method i have thisScrollView.scrollTo(0, 0);
The funny thing is, this works in the Emulator and on the Sony Ericsson Xperia, but not on the HTC Desire and Galaxy Tab. It shouldn't be related to the Android version on the devices because the method is available since API Level 1..
Anyone got any ideas?
Upvotes: 0
Views: 868
Reputation: 62519
i had this same issue and i put the call to scoll in a runnable and posted it when the UI messaging queue becomes available. I have no idea why it works.
getView().post(new Runnable() {
@Override
public void run() {
myscrollView.fullScroll(ScrollView.FOCUS_UP);
myscrollView.smoothScrollTo(0,0);
}
});
i have no clue why i need both of these calls as they do the same thing. but this worked for me but doing just one of them did not.
Upvotes: 0
Reputation: 1893
I also tried scrollTo(0,0)
on a ScrollView containing a ViewFlipper as a child. The result wasn't so much accurate.
Then I tried smoothScrollTo(0, 0);
as given below
_viewFlipperParentScrollView.fullScroll(View.FOCUS_UP);
_viewFlipperParentScrollView.pageScroll(View.FOCUS_UP);
_viewFlipperParentScrollView.smoothScrollTo(0, 0);
The result isn't fully satisfying, but much better than the one with
_viewFlipperParentScrollView.scrollTo(0, 0);
Upvotes: 1
Reputation: 9258
I usually use setSelectionAfterHeaderView for this purpose and it works on HTC devices.
Upvotes: 0