[英]scrolling to the top of a webview (Android)
在用戶點擊對象后,我有一個webview加載大文本。 我喜歡從頂部顯示的文字。 但是如果用戶在前一個文本中向下滾動,則下一個已經滾動並且不從頂部顯示。
我正在使用webView.scrollTo(0,0);
在我的webview的onPageFinished
事件中。
這在我的模擬器中工作正常,但在我的手機上,文本在中間滾動。
當使用Thread.sleep添加暫停時,它也適用於我的手機。 我在這做錯了什么?
我的代碼:
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
// Pause is needed for my physical phone S7. In Emulator there I have no problem.
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
webView.scrollTo(0,0);
super.onPageFinished(view, url);
}
});
試試這段代碼 -
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
// Pause is needed for my physical phone S7. In Emulator there I have no problem.
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
view.scrollTo(0,0);
super.onPageFinished(view, url);
}
});
實際上,你是如此接近解決方案。 關鍵是你需要在onPageFinished方法的返回視圖中設置scrollTo。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.