Reputation: 13
I'm setting up a web page inside web view. my web page have swipe down to refresh function.when my web page is in top, when i scroll drawer menu in my web page , swipe to refresh is occurring. how to solve this issue?
main activity layout code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="45dp"
android:orientation="vertical">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="10dp"
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/homeWeb"
android:layout_above="@id/navBar"/>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
MainActivity
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener(){
@Override
public void onRefresh() {
homeWeb.reload();
}
});
Upvotes: 1
Views: 1058
Reputation: 1048
Enable/Disable swipe refresh when do something with webview. Below method do same. try and let me know will it work or not.
swipe.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
swipe.setEnabled((homeWeb.getScrollY() == 0));
}
});
Upvotes: 1