Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add pull to refresh in AppBarLayout

I find most of the material is about discussing adding "pull to refresh" in the area below AppBarLayout, such as SwipeRefreshLayout, I wonder how to do this in the AppBarLayout, which means:

enter image description here

When pull down, the pull-to-refresh indicator appeaars in the AppBarLayout.

how to implement this? Thanks

=================UPDATE===================

I finally worked it out on my own way. Here is the video link recording the simple UI.

The key point is I rewrite the appbarlayout-spring-behavior from github. It's really helpeful. Simply put, I rewrited the AppBarLayoutSpringBehavior, adding a Pull-To-Refresh-Callback when draging, and add some logic to displaying the pull-to-refresh animation prevent simplely animating back to original state. After sometime, then I tell the behavior to animate back.

Though the rewriten code seems ugly, but it seems feasible. I will refactor my code to make it clean and modular

like image 297
mianlaoshu Avatar asked Jul 27 '17 14:07

mianlaoshu


2 Answers

I have wrote one nestrefresh repo which you can add pull refresh for the header same to AppBarLayout. You can add pull to refresh for child in ViewPager or pull to load more. You can use ChildCoordinatorLayout in my repo to wrap AppBarLayout if you want to use AppBarLayout only. But when scroll AppBarLayout can not refresh because of AppBarLayout has not send scroll event to parent. So you can try RefreshBarLayout in the repo.

like image 66
CN_tudou Avatar answered Sep 21 '22 17:09

CN_tudou


I finally worked it out on my own way. Here is the video link recording the simple UI.

The key point is I rewrite the appbarlayout-spring-behavior from github. It's really helpeful. Simply put, I rewrited the AppBarLayoutSpringBehavior, adding a Pull-To-Refresh-Callback when draging, and add some logic to displaying the pull-to-refresh animation prevent simplely animating back to original state. After sometime, then I tell the behavior to animate back.

Though the rewriten code seems ugly, but it seems feasible. I will refactor my code to make it clean and modular

like image 40
mianlaoshu Avatar answered Sep 23 '22 17:09

mianlaoshu