如何在刷卡时刷新布局以刷新android
每次我尝试在顶部滚动时,swipeRefresh中都有一个recycler视图。调用swipe to refresh方法并刷新布局,但我只想在滚动到屏幕顶部时刷新布局。有人能回答这个问题吗 非常感谢您的帮助,谢谢 我的布局如下所示如何在刷卡时刷新布局以刷新android,android,android-recyclerview,swiperefreshlayout,Android,Android Recyclerview,Swiperefreshlayout,每次我尝试在顶部滚动时,swipeRefresh中都有一个recycler视图。调用swipe to refresh方法并刷新布局,但我只想在滚动到屏幕顶部时刷新布局。有人能回答这个问题吗 非常感谢您的帮助,谢谢 我的布局如下所示 <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipe_container" android:layout_width="wrap_content" and
<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>
使用布局的方法
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);
}
});
我解决了我的问题。我不得不重新安排我的代码以使其正常工作。 现在,lyout在到达屏幕顶部时刷新
<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>
我正在使用setOnRefreshListener,但问题是每次我尝试向上滚动时都会调用它。当我想在到达屏幕顶部时刷新时,你可以让它一直保持刷新为什么RecyclerView
和SwiperFreshLayout
之间存在RelativeLayout
?SwipeRefreshLayout
不应该是RecyclerView
的直接父级吗?看见