如何创建只能拉出 RecyclerView 的 SwipeRefreshLayout?
How to create a SwipeRefreshLayout that only can be pulled outside the RecyclerView?
我想创建一个布局,例如主布局是一个垂直 LinearLayout
,里面是一个 TextView
和一个包裹 RecyclerView
。我想添加一个只能在 RecyclerView
之外滑动的 SwipeRefreshLayout
。
这是此布局的简单 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="40dp"
tools:context=".fragments.warehouse.WHTabOne">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAlignment="center"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
我应该把 SwipeRefreshLayout
放在哪里才能让它只在 RecyclerView
之外工作?
制作 SwipeRefreshLayout
根布局并将所有内容放入其中。示例:
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe_refresh_layout"
android:padding="40dp"
tools:context=".fragments.warehouse.WHTabOne">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAlignment="center"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
我想要的是防止 SwipeRefreshLayout
在仅在 RecyclerView
上滑动时启动,而在其他任何地方滑动时激活 SwipeRefreshLayout
。
但我发现 RecyclerView
默认覆盖 SwipeRefreshLayout
直到它到达 RecyclerView 的顶部然后它开始激活 SwipeRefreshLayout
。我认为它不会起作用,因为我的列表太短而无法注意到。现在我已经在列表中添加了更多项目,很清楚了。所以基本上,在 SwipeRefreshLayout
下添加所有内容在默认情况下是正确的,它将以正确的方式进行。
我想创建一个布局,例如主布局是一个垂直 LinearLayout
,里面是一个 TextView
和一个包裹 RecyclerView
。我想添加一个只能在 RecyclerView
之外滑动的 SwipeRefreshLayout
。
这是此布局的简单 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="40dp"
tools:context=".fragments.warehouse.WHTabOne">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAlignment="center"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
我应该把 SwipeRefreshLayout
放在哪里才能让它只在 RecyclerView
之外工作?
制作 SwipeRefreshLayout
根布局并将所有内容放入其中。示例:
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe_refresh_layout"
android:padding="40dp"
tools:context=".fragments.warehouse.WHTabOne">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAlignment="center"
android:textSize="18sp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
我想要的是防止 SwipeRefreshLayout
在仅在 RecyclerView
上滑动时启动,而在其他任何地方滑动时激活 SwipeRefreshLayout
。
但我发现 RecyclerView
默认覆盖 SwipeRefreshLayout
直到它到达 RecyclerView 的顶部然后它开始激活 SwipeRefreshLayout
。我认为它不会起作用,因为我的列表太短而无法注意到。现在我已经在列表中添加了更多项目,很清楚了。所以基本上,在 SwipeRefreshLayout
下添加所有内容在默认情况下是正确的,它将以正确的方式进行。