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: http://developer.android.com/samples/SwipeRefreshLayoutBasic/index.html
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.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
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 https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html 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.