Конфликт SwipeRefreshLayout с прокруткой вниз в WebView - PullRequest
0 голосов
/ 13 июня 2018

В моем приложении 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>

Можете ли вы помочь мне понять, как я могу разделить эти две функции прокрутки?

Редактировать: Посмотрел здесь это не отвечает на мой вопрос

1 Ответ

0 голосов
/ 15 декабря 2018

используйте 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.
    }
}
...