Android-下拉刷新整个页面

Android-下拉刷新整个页面,android,android-layout,pull-to-refresh,Android,Android Layout,Pull To Refresh,我正在开发一个功能,它可以让用户在应用程序中的任何位置下拉一个页面,以检查他们是否与数据库服务器建立了连接。我一直关注这个网站,但它需要滚动查看或列表查看功能。我所有的布局都是相对的。有没有一种方法可以在不将整个布局转换为滚动视图的情况下实现这一点 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/too

我正在开发一个功能,它可以让用户在应用程序中的任何位置下拉一个页面,以检查他们是否与数据库服务器建立了连接。我一直关注这个网站,但它需要滚动查看或列表查看功能。我所有的布局都是相对的。有没有一种方法可以在不将整个布局转换为滚动视图的情况下实现这一点

<RelativeLayout 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"
    tools:context="com.infomaninc.appinlisv2.NewClaim">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:id="@+id/rlHeader" >
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#1BB52D"
    android:gravity="center"
    android:padding="3dp"
    android:id="@+id/rlFooter" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/footer_value"
        android:id="@+id/tvFooter"
        android:textColor="#fff"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/app_name"
        android:id="@+id/tvLoggedOn"
        android:textColor="#fff"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>
</RelativeLayout>

不要介意代码的内容。这只是一页的一小段。 如果我的页面看起来像这样,我将如何实现下拉刷新


到目前为止,我已经学习了本教程:

我不确定是否必须使用
RelativeLayout
,但您可以将所有
RelativeLayout
放在
滚动视图中。然后添加
OnScrollListener
以刷新

<ScrollView>   

    <RelativeLayout> 
           // all your relativelayout
    </RelativeLayout> 

 </ScrollView> 
更新


示例给出了向下滚动时检测
ScrollView
到达底部或向上滚动时检测到顶部。可以使用scrollview和子属性创建刷新逻辑。

您还可以查找
SwipeRefreshLayout
。虽然它需要一个
ScrollView/ListView
,但这并不重要,因为所有数据都显示在一个页面中。只需记住在
滚动视图中设置
android:fillViewport=“true”
,就可以了。您可以按以下步骤进行操作:

    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.your_id_for_swiperefreshlayout);
    swipeRefreshLayout.setOnRefreshListener(this);
    @Override
    public void onRefresh() {
        //reload the data
    }

只有从顶部向下拉动,onScrollChanged才会运行吗?或者只要您滚动它,它就会运行?您是否可以添加任何内容来共享如何执行刷新逻辑、检测您是否从顶部滚动?@OrdinaryProgrammer当您向上或向下滚动时,它将运行。@o0rebelious0o Scrollview将提供有关顶部、底部、宽度和高度的信息。从那里您可以添加刷新逻辑。稍后我会用刷新逻辑更新我的答案。我确实这样做了,但它只是把我的应用搞砸了。它消耗了太多的帧,谁知道原因是什么。在我这么做之后,我的应用程序一直崩溃。悲哀,这是可以理解的。我可以看一下同样的logcat输出吗?
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.your_id_for_swiperefreshlayout);
    swipeRefreshLayout.setOnRefreshListener(this);
    @Override
    public void onRefresh() {
        //reload the data
    }