English| Chinese
An efficient Android refresh library that theoretically supports all views and is more powerful and easy to use than the official SwipeRefreshLayout. Some of the code for this open source library comes from Android-ultra-pull-to-refresh. Thank you so much for providing such a great open source project!
Features:
- All views are theoretically supported and can be adapted efficiently according to specific requirements.
- Support nesting sliding, complete implementation of NestedScrollingChild, NestedScrollingParent interface, play CoordinatorLayout.
- Inherit directly from ViewGroup, have excellent performance, support FameLayout like features (Gravity, Margin).
- Supports automatic refresh, automatic pull-up loading, and more automatic loading (not recommended. Adapter is recommended. You can customize the logic callback to realize more preloading).
- Support rebound across the border.
- Support for drawer effects (that is, the refresh view is anchored below the content view).
- Support refreshing view customization styles,STYLE_DEFAULT(default does not change size), STYLE_SCALE(dynamic change size)
- Support level 2 refresh event (TwoLevelSmoothRefreshLayout), PS: taobao, jingdong activities on the second floor.
- Support ListView, GridView, RecyclerView to load more smooth scrolling.
- Margin support for content view,PS: No Margin effect in scrolling? SmoothRefreshLayout doesn’t have this problem.
- Supports multi-state views,STATE_CONTENT(default state), STATE_ERROR(exception state),STATE_EMPTY(empty state), and STATE_CUSTOM(custom state).
- Rich callback interface and debugging information, leveraging existing apis to achieve rich effects.
Download Demo apk
Update log
Update log
The snapshot
-
Test QQ activity style
-
Test level 2 flush
-
Contains the FrameLayout
-
Contains the TextView
-
Contains a ListView
-
Contains the GridView
-
Contains RecyclerView
-
Contains the ViewPager
-
Contains the WebView
-
CoordinatorLayout
-
Jump back mode
-
Test nested sliding
use
repositories { ... Dependencies maven {url 'https://jitpack.io'}} {the compile 'com. Making. DKZWM: SmoothRefreshLayout: 1.4.5'}
Copy the code
Configure in Xml
<? The XML version = "1.0" encoding = "utf-8"? > <me.dkzwm.widget.srl.SmoothRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/smoothRefreshLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="match_parent" android:layout_height="match_parent"/> </me.dkzwm.widget.srl.SmoothRefreshLayout>
Copy the code
Earlier than v1.4.1
<? The XML version = "1.0" encoding = "utf-8"? > <me.dkzwm.smoothrefreshlayout.SmoothRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/smoothRefreshLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="match_parent" android:layout_height="match_parent"/> </me.dkzwm.smoothrefreshlayout.SmoothRefreshLayout>
Copy the code
SmoothRefreshLayout refreshLayout = (SmoothRefreshLayout)findViewById(R.id.smoothRefreshLayout); refreshLayout.setMode(SmoothRefreshLayout.MODE_BOTH); refreshLayout.setHeaderView(new ClassicHeader(this)); refreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() { @Override public void onRefreshBegin(boolean isRefresh) { mHandler.postDelayed(new Runnable() { @Override public void run() { refreshLayout.refreshComplete(); }}, 4000); }});
Copy the code
Customize the refresh view
public interface IRefreshView { byte TYPE_HEADER = 0; byte TYPE_FOOTER = 1; byte STYLE_DEFAULT = 0; byte STYLE_SCALE = 1; /** * returns a header view or a tail view */ int getType(); /** * Return this; */ View getView(); /** * Get view style, now support 2 styles, default style and scale style. */ int getStyle(); /** * Get the custom height of the view. If the view style is STYLE_SCALE, an exact value greater than 0 must be returned. /** * Remove finger from screen */ void onFingerUp(SmoothRefreshLayout, IIndicator); /** * reset the view */ void onReset(SmoothRefreshLayout); /** * reconfigure the view, ready to refresh */ void onRefreshPrepare(SmoothRefreshLayout); /** * start refresh */ void onRefreshBegin(SmoothRefreshLayout, IIndicator); /** * refresh complete */ void onRefreshComplete(SmoothRefreshLayout layout, Boolean isSuccessful); /** * Void onRefreshPositionChanged(SmoothRefreshLayout, byte Status, IIndicator); }
Copy the code
Add a custom refresh view
- Global static code construction
SmoothRefreshLayout.setDefaultCreator(new IRefreshViewCreator() {
@Override
public void createHeader(SmoothRefreshLayout layout) {
ClassicHeader header = new ClassicHeader(layout.getContext());
layout.setHeaderView(header);
}
@Override
public void createFooter(SmoothRefreshLayout layout) {
ClassicFooter footer = new ClassicFooter(layout.getContext());
layout.setFooterView(footer);
}
});
Copy the code
- Dynamic code addition
setHeaderView(@NonNull IRefreshView header);
setFooterView(@NonNull IRefreshView footer);
Copy the code
- SmoothRefreshLayout will determine if the added View implements the IRefreshView interface
SmoothRefreshLayout configures itself
The name of the | type | describe |
---|---|---|
sr_content | reference | Specify the resource ID of the content view |
sr_resistance | float | Movement damping when moving a view refresh (default:1.65 f ) |
sr_resistance_of_footer | float | Movement damping when moving Footer view (default:1.65 f ) |
sr_resistance_of_header | float | Movement damping when moving Header views (default:1.65 f ) |
sr_ratio_of_refresh_height_to_refresh | float | Ratio of position to the height of the refreshed view when the refresh is triggered (default:1.1 f ) |
sr_ratio_of_header_height_to_refresh | float | Height ratio of position to Header view when triggering refresh (default:1.1 f ) |
sr_ratio_of_footer_height_to_refresh | float | Footer view height ratio of locations that trigger more loads (default:1.1 f ) |
sr_offset_ratio_to_keep_refresh_while_Loading | float | Height ratio of view position held in refresh to refreshed view (default:1f ), the value of this property must be less than or equal to the trigger refresh height ratio to be effective |
sr_offset_ratio_to_keep_header_while_Loading | float | Keep the height ratio of view position to Header view in refresh (default:1f ), the value of this property must be less than or equal to the trigger refresh height ratio to be effective |
sr_offset_ratio_to_keep_footer_while_Loading | float | Keep the height ratio of view position to Footer view in refresh (default:1f ), the value of this property must be less than or equal to the trigger refresh height ratio to be effective |
sr_can_move_the_max_ratio_of_refresh_height | float | Maximum distance traveled relative to the height of the refreshed view (default:0f Is not triggered.) |
sr_can_move_the_max_ratio_of_header_height | float | Maximum distance traveled to Header view height ratio (default:0f Is not triggered.) |
sr_can_move_the_max_ratio_of_footer_height | float | Maximum distance traveled to Footer view height ratio (default:0f Is not triggered.) |
sr_duration_to_close_of_refresh | integer | Specifies the length of time to shrink the refresh view to its starting position (default:500 ) |
sr_duration_to_close_of_header | integer | Specifies the length of time to shrink the Header view to its starting position (default:500 ) |
sr_duration_to_close_of_footer | integer | Specifies how long the Footer view should shrink to its starting position (default:500 ) |
sr_duration_of_back_to_keep_refresh_pos | integer | Set the time to roll back to the position where the view is kept refreshed (default:200 ) |
sr_duration_of_back_to_keep_header_pos | integer | Set the time to rollback to hold the Header view (default:200 ) |
sr_duration_of_back_to_keep_header_pos | integer | Set the time to roll back to the Footer view position (default:200 ) |
sr_enable_pin_content | boolean | Fixed content view (default:false ) |
sr_enable_keep_refresh_view | boolean | Keep the view where it should be in refresh (default:true ) |
sr_enable_pull_to_refresh | boolean | Pull refresh, pull down or pull up to trigger refresh position to trigger refresh immediately (default:false ) |
sr_enable_over_scroll | boolean | Bounceback (Default:true ), users need to set their own content viewoverScrollMode 为 never In order to achieve optimal results |
sr_empty_layout | reference | Specifies the ID of the layout resource in the empty state |
sr_error_layout | reference | Specify the ID of the layout resource in the abnormal state |
sr_custom_layout | reference | Specify the layout resource ID in the custom state |
sr_state | enum | Status Settings (default:STATE_CONTENT ) |
sr_enable_refresh | boolean | Sets whether to enable pull-down refresh (default:ture ) |
sr_enable_load_more | boolean | Sets whether to enable loading more (default:false ) |
Versions later than V1.4.5
The name of the | type | describe |
---|---|---|
sr_enable_two_level_refresh | boolean | Sets whether to enable secondary refresh (default:true ) |
The name of the | type | describe |
---|---|---|
sr_enable_two_level_pull_to_refresh | boolean | Sets whether to enable secondary refresh (default:true ) |
SmoothRefreshLayout supports configuration of other views inside the package
The name of the | type | describe |
---|---|---|
layout_gravity | flag | Specify alignment properties for other wrapped views (non-targetView, non-refreshView) |
The name of the | parameter | describe |
---|---|---|
setHeaderView | IRefreshView | Configuring the Header View |
setFooterView | IRefreshView | Configuring the tail View |
setContentView | int,View | Configure the content view. Parameter 1: sets the state of the content view. Parameter 2: sets the content view corresponding to the state |
setState | int | Configuring the Current Status |
setState | int,boolean | Configure the current state, parameter 1: current state, parameter 2: whether to use gradient animation transition |
setDisableWhenHorizontalMove | boolean | Set this property to true when an internal view contains a landscape slide view (for example, ViewPager).false ) |
setEnableNextPtrAtOnce | boolean | After refreshing, refresh again |
setOverScrollDurationRatio | float | Bounding rebound time ratio: the real moving time can be obtained by multiplying the moving time obtained when triggering the bounding by this ratio, and the maximum moving time cannot exceedmMaxOverScrollDuration (Default:0.5 f ). |
setMaxOverScrollDuration | int | Set the maximum time for bounding animation (default:500 ) |
setMinOverScrollDuration | int | Set the minimum time for bounding animation (default:150 ) |
setResistance | float | Movement damping when moving a view refresh (default:1.65 f ) |
setResistanceOfFooter | float | Movement damping when moving Footer view (default:1.65 f ) |
setResistanceOfHeader | float | Movement damping when moving Header views (default:1.65 f ) |
setRatioOfRefreshViewHeightToRefresh | float | Ratio of position to the height of the refreshed view when the refresh is triggered (default:1.1 f ) |
setRatioOfHeaderHeightToRefresh | float | Height ratio of position to Header view when triggering refresh (default:1.1 f ) |
setRatioOfFooterHeightToRefresh | float | Footer view height ratio of locations that trigger more loads (default:1.1 f ) |
setOffsetRatioToKeepRefreshViewWhileLoading | float | Height ratio of view position held in refresh to refreshed view (default:1f ), the value of this property must be less than or equal to the trigger refresh height ratio to be effective |
setOffsetRatioToKeepHeaderWhileLoading | float | Keep the height ratio of view position to Header view in refresh (default:1f ), the value of this property must be less than or equal to the trigger refresh height ratio to be effective |
setOffsetRatioToKeepFooterWhileLoading | float | Keep the height ratio of view position to Footer view in refresh (default:1f ), the value of this property must be less than or equal to the trigger refresh height ratio to be effective |
setCanMoveTheMaxRatioOfRefreshViewHeight | float | Maximum distance traveled relative to the height of the refreshed view (default:0f Is not triggered.) |
setCanMoveTheMaxRatioOfHeaderHeight | float | Maximum distance traveled to Header view height ratio (default:0f Is not triggered.) |
setCanMoveTheMaxRatioOfFooterHeight | float | Maximum distance traveled to Footer view height ratio (default:0f Is not triggered.) |
setDurationToClose | int | Specifies the length of time to shrink the refresh view to its starting position (default:500 ) |
setDurationToCloseHeader | int | Specifies the length of time to shrink the Header view to its starting position (default:500 ) |
setDurationToCloseFooter | int | Specifies how long the Footer view should shrink to its starting position (default:500 ) |
setDurationOfBackToKeepRefreshViewPosition | integer | Set the time to roll back to the position where the view is kept refreshed (default:200 ) |
setDurationOfBackToKeepHeaderPosition | integer | Set the time to rollback to hold the Header view (default:200 ) |
setDurationOfBackToKeepFooterPosition | integer | Set the time to roll back to the Footer view position (default:200 ) |
setEnablePinContentView | boolean | Fixed content view (default:false ) |
setEnabledPullToRefresh | boolean | Pull refresh, pull down or pull up to trigger refresh position to trigger refresh immediately (default:false ) |
setEnableOverScroll | boolean | Bounceback (Default:true ), users need to set their own content viewoverScrollMode 为 never In order to achieve optimal results |
setEnabledInterceptEventWhileLoading | boolean | Blocking unresponsive touch operations in refresh (default:false ) |
setEnableHeaderDrawerStyle | boolean | Header drawer style, where the Header view is under the content view (default:false ) |
setEnableFooterDrawerStyle | boolean | Footer drawer style, i.e. Footer view under content view (default:false ) |
setDisablePerformRefresh | boolean | Turn off triggering Header refresh (default:false ) |
setDisablePerformLoadMore | boolean | Turn off triggering Footer refresh (default:false ) |
setEnableLoadMoreNoMoreData | boolean | Set Footer without more data that option is settrue Is equivalent at the Frame layersetDisablePerformLoadMore Set totrue , but the custom view can change the view style according to the flag bit.ClassicFooter Support for this property is implemented by default (default:false ) |
setDisableRefresh | boolean | Disable Header refresh (default:false ) |
setDisableLoadMore | boolean | Disable Footer refresh (default:false ) |
setEnableKeepRefreshView | boolean | Keep the view where it should be in refresh (default:true ) |
setEnableScrollToBottomAutoLoadMore | boolean | Auto load from bottom (default:false ) |
setEnablePinRefreshViewWhileLoading | boolean | Fixed the refresh view to where it should stay and did not respond to movement, i.e., Material style (default:false ), the setting premise is turned onsetEnablePinContentView andsetEnableKeepRefreshView 2 options, otherwise the runtime will throw an exception |
SmoothRefreshLayout callback
The name of the | parameter | describe |
---|---|---|
setOnRefreshListener | T extends OnRefreshListener | Set the refresh event listening callback |
setOnStateChangedListener | OnStateChangedListener | Set the state change callback |
addOnUIPositionChangedListener | OnUIPositionChangedListener | Add listening callbacks for view position changes |
removeOnUIPositionChangedListener | OnUIPositionChangedListener | Removes listening callbacks for view position changes |
setOnLoadMoreScrollCallback | OnLoadMoreScrollCallback | Set the callback for smooth scrolling after the Footer finishes refreshing |
setOnPerformAutoLoadMoreCallBack | OnPerformAutoLoadMoreCallBack | Setting triggers automatic loading of more conditional callbacks if the callback is calledcanAutoLoadMore() Method returnstrue More loads are immediately triggered |
setOnChildScrollUpCallback | OnChildScrollUpCallback | Set to check if the content view is inside the top callback (SmoothRefreshLayout)canChildScrollUp() Methods) |
setOnChildScrollDownCallback | OnChildScrollDownCallback | Set to check if the content view is inside the bottom callback (SmoothRefreshLayout)canChildScrollDown() Methods) |
setOnHookHeaderRefreshCompleteCallback | OnHookUIRefreshCompleteCallBack | Set the Hook callback for the completion of the Header refresh to delay completion of the refresh |
setOnHookFooterRefreshCompleteCallback | OnHookUIRefreshCompleteCallBack | Set the Hook callback for Footer completion to delay completion of the refresh |
The name of the | parameter | describe |
---|---|---|
Debug (static method) | boolean | The Debug switch |
SetDefaultCreator (Static method) | IRefreshViewCreator | Sets the refresh view creator, who is called to build the refresh view if no refresh view is specifically specified and the set mode requires the refresh view |
refreshComplete | No arguments | The refresh is complete and the status of the last refresh is set to success |
refreshComplete | boolean | When the refresh is complete, parameter: Set whether the last refresh is successful |
refreshComplete | boolean,long | When the refresh is complete, parameter 1: set whether the refresh succeeded in the last refresh. Parameter 2: set the delay time for resetting the refresh state (the refresh completion callback of the refresh view will be triggered first, but the library is still in the refresh state during the delay) |
refreshComplete | long | Refresh is complete and the last refresh status is set as success. Parameter: Set the delay time for resetting the refresh state (the refresh completion callback of the refresh view will be triggered first, but the library is still in the refresh state during the delay) |
setLoadingMinTime | long | Set the minimum interval between the start and end of the refresh (default:500 ), parameter: time difference |
autoRefresh | No arguments | Automatically triggers Header refresh, immediately triggers the refresh event and scrolls to the trigger Header refresh location |
autoRefresh | boolean | Trigger Header refresh automatically. Parameter: Whether to trigger the refresh event immediately and scroll to the trigger Header refresh position |
autoRefresh | boolean,boolean | Trigger the refresh of the Header automatically. Parameter 1: whether to trigger the refresh event immediately. Parameter 2: Whether to scroll to the position that triggers the refresh of the Header |
autoLoadMore | No arguments | Automatically triggers a Footer refresh, immediately triggering the refresh event and scrolling to the Footer refresh trigger position |
autoLoadMore | boolean | Automatic trigger Footer refresh, parameter: whether to trigger the refresh event immediately, will scroll to trigger Footer refresh position |
autoLoadMore | boolean,boolean | Footer refresh is automatically triggered. Parameter 1: whether to trigger the refresh event immediately. Parameter 2: Whether to scroll to the Footer refresh position |
setLoadMoreScrollTargetView | View | Set the Footer moves, the content of the response motion event view, for example in SmoothRefreshLayout a CoordinatorLayout CoordinatorLayout AppbarLayout, RecyclerView etc, The more you load the RecyclerView that you want to move instead of CoordinatorLayout, you can change the RecyclerView to TargetView |
TwoLevelSmoothRefreshLayout Java attribute set method
The name of the | parameter | describe |
---|---|---|
setRatioOfHeaderHeightToHintTwoLevelRefresh | float | Sets the ratio of the position to the height of the Header view when the secondary refresh prompt is triggered |
setRatioOfHeaderHeightToTwoLevelRefresh | float | Sets the ratio of the position to the height of the Header view when the secondary refresh is triggered |
setOffsetRatioToKeepTwoLevelHeaderWhileLoading | float | Hold the height ratio of view position to Header view in secondary refresh (default:1f ) |
setDisableTwoLevelRefresh | boolean | Set whether to turn off secondary refresh (default:false ) |
setDurationOfBackToKeepTwoLevelHeaderViewPosition | int | Set the time to roll back to the position where the second level refresh Header view is held (default:500 ) |
setDurationToCloseTwoLevelHeader | int | Header Specifies the time at which the rollback to the starting position is completed.500 ) |
The name of the | parameter | describe |
---|---|---|
autoTwoLevelRefreshHint | No arguments | Automatically triggers the secondary refresh prompt and scrolls to the trigger prompt position and then rolls back to the starting position |
autoTwoLevelRefreshHint | int | Automatically trigger the secondary refresh prompt and scroll to the trigger prompt position and stay for the specified time. Parameter: Stay for the specified time |
autoTwoLevelRefreshHint | boolean | Automatic trigger secondary refresh prompt Whether to roll back to the starting position after the trigger prompt. Parameter: Whether to roll back to the trigger position |
autoTwoLevelRefreshHint | boolean,int | Automatically trigger the secondary refresh prompt, parameter 1: whether to scroll to the trigger position, parameter 2: how long to stay |
Thanks
- liaohuqiu android-Ultra-Pull-To-Refresh
- pnikosis material-progress
License
MIT License
Copyright (c) 2017 dkzwm
Copyright (c) 2015 liaohuqiu.net
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Copy the code