Today, I saw the term SwipeRefreshLayout on Google +. I searched for it and found that it was a new widget added to the google update sdk, so I had to learn it first.
SwipeRefreshLayout
SwipeRefreshLayout literally refers to the pull-down refresh layout, inherited from ViewGroup, under the support v4 compatibility package, but you must upgrade your support library version to 19.1. When it comes to pull-down refresh, everyone must be familiar with ActionBarPullToRefresh. Now google has launched a more official pull-down refresh component, which is undoubtedly a good news for developers. You can use this component to easily refresh Google Now. For details, see:
Main Method
- SetOnRefreshListener (OnRefreshListener): adds a Listener for the layout.
- SetRefreshing (boolean): display or hide the refresh progress bar
- IsRefreshing (): checks whether a refresh status is in progress.
- SetColorScheme (): Set the color topic of the progress bar. You can set up to four
Xml layout File
The layout file is simple. You only need to add SwipeRefreshLayout to the outermost layer, and then its child is a scrollable view, such as ScrollView or ListView. For example, copy the code
Activity Code
Copy code
The above code is very simple. You only need to add a listener to SwipeRefreshLayout. It is worth noting that the setColorScheme method sets the color of the refresh progress bar and can only set up to four types of loop display, the first one by default is the color progress bar loaded with user gestures.
Source code
The demo is written on github at: SwipeRefreshLayoutDemo.
Summary
Google is constantly improving its own sdk and launching more and more components. The goal is to make development simpler and design more unified. This may be the future direction of google, this is undoubtedly a good news for developers.