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.

Update log

The snapshot

use

Configure in Xml

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

Customize the refresh view

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:0fIs not triggered.)
sr_can_move_the_max_ratio_of_header_height float Maximum distance traveled to Header view height ratio (default:0fIs not triggered.)
sr_can_move_the_max_ratio_of_footer_height float Maximum distance traveled to Footer view height ratio (default:0fIs 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 viewoverScrollModeneverIn 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)
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)

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 returnstrueMore 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

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)

Thanks

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