简体   繁体   English

ScrollView不在ViewFlipper中滚动到顶部

[英]ScrollView not scrolling to top in ViewFlipper

I made a ViewFlipper that navigates between articles of news I parse from the web. 我制作了一个ViewFlipper ,可以在我从网络解析的新闻文章之间导航。

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. 一切正常,但是当我向下滚动到当前项目然后导航到下一个/上一个项目时, ScrollView不会滚动到新文章项目的顶部。 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); 在我的onClick(View v)方法的最后,我有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. 有趣的是,它可以在模拟器和索尼爱立信Xperia上使用,但不能在HTC Desire和Galaxy Tab上使用。 It shouldn't be related to the Android version on the devices because the method is available since API Level 1.. 它不应该与设备上的Android版本相关,因为该方法自API级别1开始可用。

Anyone got any ideas? 任何人有任何想法吗?

I also tried scrollTo(0,0) on a ScrollView containing a ViewFlipper as a child. 我还在包含ViewFlipper的ScrollView上尝试了scrollTo(0,0)作为子项。 The result wasn't so much accurate. 结果不是那么准确。

Then I tried smoothScrollTo(0, 0); 然后我尝试了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. 我遇到了同样的问题,当UI消息队列可用时,我将对scoll的调用放在了可运行的位置并发布了它。 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设备上使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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