当 RecyclerView 为空时将 SwipeRefreshLayout 添加到 RecyclerView header
Add SwipeRefreshLayout to RecyclerView when it has an empty header
我已将 headerView 添加到我的 RecyclerView 中,如以下问题的答案所述:Is there an addHeaderView equivalent for RecyclerView?
header 是一个空视图,将隐藏在 toolBar 下。
<?xml version="1.0" encoding="utf-8"?>
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
问题出在SwipeRefreshLayout的地方。它将从工具栏下的Header开始,因此它部分隐藏在工具栏下。
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.test.android.client.fragment.MyFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
我该如何解决这个问题?
我发现 setProgressViewOffset 方法是一种解决方法
但我仍然无法弄清楚如何获得默认的开始和结束位置。 (将在方法中传递的参数)
我已将 headerView 添加到我的 RecyclerView 中,如以下问题的答案所述:Is there an addHeaderView equivalent for RecyclerView?
header 是一个空视图,将隐藏在 toolBar 下。
<?xml version="1.0" encoding="utf-8"?>
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
问题出在SwipeRefreshLayout的地方。它将从工具栏下的Header开始,因此它部分隐藏在工具栏下。
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.test.android.client.fragment.MyFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
我该如何解决这个问题?
我发现 setProgressViewOffset 方法是一种解决方法
但我仍然无法弄清楚如何获得默认的开始和结束位置。 (将在方法中传递的参数)