[英]how to refresh layout in on swipe to refresh android
I have a recycler view inside a swipeRefresh every time i try to scroll on top the swipe to refresh method gets called and the layout is refreshed, but i want to refresh the layout only on scrolling to the top of the screen. 每当我尝试在顶部滑动滚动以刷新方法时,都会在swipeRefresh中有一个回收者视图,并且刷新了布局,但是我只想在滚动到屏幕顶部时刷新布局。 Does anybody have an answer to this question.
有人对此问题有答案吗?
Any help is appreciated, Thank you 任何帮助表示赞赏,谢谢
My layout is as shown below. 我的布局如下图所示。
<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>
I solved my problem. 我解决了我的问题。 I had to rearrange my code to get it working.
我必须重新排列我的代码才能使其正常工作。 Now the lyout refreshes on on reaching the top of the screen.
现在,配置信息刷新到屏幕顶部。
<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>
Use setOnRefreshListener method of SwipeRefreshLayout 使用SwipeRefreshLayout的setOnRefreshListener方法
upload_swipe_refresh_layout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
webServiceCall();
upload_swipe_refresh_layout.setRefreshing(false);
}
});
For keep refreshing 为了保持刷新
upload_swipe_refresh_layout.post(new Runnable() {
@Override
public void run() {
upload_swipe_refresh_layout.setRefreshing(true);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.