view raw
Simon Simon - 7 months ago 54
Android Question

SwipeRefreshLayout: Swipe progress animation

I'm quite new to android and I'm exploring the sample code on google website. The code I'm on currently is the SwipeRefreshLayout:

In the code, we see the SwipeRefreshLayout being executed for a listview, so in other words, if you drag down the list view, the method is triggered and the listview refreshes itself.


android:layout_height="match_parent" />


What is confusing me is that there is no layout in the code for the progress animation bar that gets displayed at the top of the listview when you drag it down. Do you think that the SwipeRefreshLayout automatically generates a progress animation bar when you drag it down without requiring the user to specify any layout in xml for it?

For example, if one wants to put padding at both ends of the progress animation bar, so that the animation doesn't touch the ends of the screen when you refresh, how would one do it?

The doesn't really say anything about it.


You can't change the animation.

In SwipeRefreshLayout you can't customize much; I believe this is an attempt of Google to get developers stick to common patterns. What you can style are the four colors of the animation, specified with setColorScheme().

SwipeRefreshLayout takes care to show its predefined animation at its top for you. This can be when canChildScrollUp() returns false and user 'pulls down', or when you set setRefreshing(true). Turn off the animation with setRefreshing(false). Put your logic in the method onRefreshing() of the listener. Override canChildScrollUp() if you put something that is not a ListView in your SwipeRefreshLayout. You should be good to go from here.