【问题标题】:how to refresh layout in on swipe to refresh android如何在滑动时刷新布局以刷新android
【发布时间】:2016-07-15 06:37:34
【问题描述】:

每次我尝试在顶部滚动时,我在 swipeRefresh 中有一个回收器视图,会调用 swipe to refresh 方法并刷新布局,但我只想在滚动到屏幕顶部时刷新布局。有没有人回答这个问题。

感谢您的帮助,谢谢

我的布局如下图。

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipe_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:id="@+id/rel"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/toolbar"
            android:scrollbars="vertical" />
    </RelativeLayout>

</android.support.v4.widget.SwipeRefreshLayout>

【问题讨论】:

标签: android android-recyclerview swiperefreshlayout


【解决方案1】:

我解决了我的问题。我不得不重新排列我的代码以使其正常工作。 现在,布局会在到达屏幕顶部时刷新。

<RelativeLayout
    android:id="@+id/rel"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_collapseMode="pin"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/toolbar">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/swipe_container"
            android:scrollbars="vertical" />

    </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>

【讨论】:

    【解决方案2】:

    使用SwipeRefreshLayout的setOnRefreshListener方法

    upload_swipe_refresh_layout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
    
                webServiceCall();
                upload_swipe_refresh_layout.setRefreshing(false);
            }
        });
    

    为了保持清爽

    upload_swipe_refresh_layout.post(new Runnable() {
        @Override
        public void run() {
            upload_swipe_refresh_layout.setRefreshing(true);
        }
    });
    

    【讨论】:

    • 我正在使用 setOnRefreshListener,但每次我尝试向上滚动时都会调用它的问题。而我想在到达屏幕顶部时刷新。
    • 那么你就可以一直保持清爽
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多