Как добавить тягу, чтобы обновить в макете координатора - PullRequest
3 голосов
/ 06 ноября 2019

У меня есть AppBar и RecyclerView в CoordiantorLayout. SwipeToRefresh должен быть полноэкранным, но RecyclerView тогда не прокручивать вниз.

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="128dp"/>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</androidx.coordinatorlayout.widget.CoordinatorLayout>

oid

Как добавить полноэкранный режим для обновления в макете Координатора без библиотеки.

Ответы [ 2 ]

3 голосов
/ 06 ноября 2019

Я добавляю swipetorefresh верхнего уровня, как ответ выше. И я исправляю проблему с прокруткой вверх с помощью кода ниже. Благодаря mohammadReza:)

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener(){
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            int topRowVerticalPosition =
                    (recyclerView == null || recyclerView.getChildCount() == 0) ? 0 : recyclerView.getChildAt(0).getTop();
            swipeRefreshLayout.setEnabled(topRowVerticalPosition >= 0);

        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
        }
    });
3 голосов
/ 06 ноября 2019

попробуйте установить SwipeRefreshLayout в качестве корневого родителя следующим образом:

<?xml version="1.0" encoding="utf-8"?>

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />


        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="128dp" />

        </com.google.android.material.appbar.AppBarLayout>


    </androidx.coordinatorlayout.widget.CoordinatorLayout>

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
...