gpt4 book ai didi

android - SwipeRefreshLayout 与 WebView 中向下滚动冲突

转载 作者:行者123 更新时间:2023-12-02 16:34:43 31 4
gpt4 key购买 nike

在我的 WebView 应用程序中,SwipeRefreshLayout 不起作用,因为当我向下滚动时,它会触发页面重新加载功能。我认为一种解决方案是限制下拉刷新布局。我尝试了这个,但似乎不起作用。

这是我的实现:

Java 文件

SwipeRefreshLayout mySwipeRefreshLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mySwipeRefreshLayout = (SwipeRefreshLayout)this.findViewById(R.id.swipeContainer);

String URL = "my_url";
mWebView = (WebView) findViewById(R.id.enyakin);
WebSettings webSettings = mWebView.getSettings();
mWebView.loadUrl(URL);
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {

// Phone call function if this matters
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

if (url.startsWith("tel:"))
{
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(intent);
return true;
}
view.loadUrl(url);
return true;
}
});

mySwipeRefreshLayout.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
mWebView.reload();
if (null != mySwipeRefreshLayout) {
mySwipeRefreshLayout.setRefreshing(false);
}
}
}
);

XML 文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.google.firebase.quickstart.fcm.MainActivity"
tools:showIn="@layout/activity_main">

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fillViewport="true">
<WebView
android:id="@+id/enyakin"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>

你能帮我理解如何分离这两个滚动功能吗?

编辑:看了here这并不能回答我的问题

最佳答案

使用setOnChildScrollUpCallback控制何时触发刷新。

这是 kotlin 中的示例代码。

mySwipeRefreshLayout.apply {
setOnRefreshListener {
// Handle refresh
}

setOnChildScrollUpCallback {parent, child ->
// Return true to disable swiping to refresh.
// You can get scrolling position of nested scroll view and only return true when it is larger than 0.
}
}

关于android - SwipeRefreshLayout 与 WebView 中向下滚动冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50836295/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com