I am building an android app with a webview in the MainActivity wrapped inside a swipe refresh layout.
Now what I wanna do is if the webview is scrolled down(even a small distance!), I want to hide the swipe refresh layout. And if the webview is not scrolled, i.e., its content is at the top, I want to show the swipe refresh layout!
This is because if the webview is scrolled, it causes a problem that when i scroll up, the swipe refresh layout gets called and doesn't let the webview to scroll up.
I have tried this:
final int content_height = (int) Math.floor(webView.getContentHeight() * getResources().getDisplayMetrics().density);
webView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if(scrollY!=content_height) {
swipeRefreshLayout.setVisibility(View.GONE);
}
else {
swipeRefreshLayout.setVisibility(View.VISIBLE);
}
}
});
Any help would be appreciated!
from WebView's scroll distance from top
No comments:
Post a Comment