简体   繁体   中英

ScrollView not scrolling to top in ViewFlipper

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?

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);

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.

我通常为此目的使用setSelectionAfterHeaderView ,它可以在HTC设备上使用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM