SmoothRefreshLayout
?????Android???????????????????SwipeRefreshLayout????????.
??????????? android-Ultra-Pull-To-Refresh.
?????????????????
??:
- ???????????????????????.
- ??????,?????NestedScrollingChild?NestedScrollingParent ??,??CoordinatorLayout.
- ?????ViewGroup,???????,???FameLayout????Gravity?Margin).
- ???????????????????????????????Adapter???????????????????????.
- ??????.
- ??????????,STYLE_DEFAULT(???????)?STYLE_SCALE(?????????????????????????)?STYLE_PIN(??????????????????)?STYLE_FOLLOW_SCALE(???????????????????????????????????????)?STYLE_FOLLOW_PIN(??????????????????????????)?STYLE_FOLLOW_CENTER(??????????????????????????????????????).
- ?????????TwoLevelSmoothRefreshLayout??PS:?????????.
- ??????(HorizontalSmoothRefreshLayout).
- ??ListView?GridView?RecyclerView?????????.
- ???????,STATE_CONTENT(????)?STATE_ERROR(????),STATE_EMPTY(???),STATE_CUSTOM(?????).
- ????????????,?????Api???????.
????
?? Demo.apk
????
?????????
????
??
??
Gradle
repositories {
...
maven {
url 'https://jitpack.io'
}
}
dependencies {
//????????????????????????
compile 'com.github.dkzwm.SmoothRefreshLayout:core:1.5.0.3'
//?????????
compile 'com.github.dkzwm.SmoothRefreshLayout:ext-two-level:1.5.0.3'
//?????????
compile 'com.github.dkzwm.SmoothRefreshLayout:ext-horizontal:1.5.0.3'
}
?Xml???
<?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/refreshLayout" 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>
Java????
SmoothRefreshLayout refreshLayout = (SmoothRefreshLayout)findViewById(R.id.smoothRefreshLayout);
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);
}
}
);
???????
????
public interface IRefreshView <T extends IIndicator> {
byte TYPE_HEADER = 0;
byte TYPE_FOOTER = 1;
byte STYLE_DEFAULT = 0;
byte STYLE_SCALE = 1;
byte STYLE_PIN = 2;
byte STYLE_FOLLOW_SCALE = 3;
byte STYLE_FOLLOW_PIN = 4;
byte STYLE_FOLLOW_CENTER = 5;
/**
* ?????????????;
*/
int getType();
/**
* ??????View??????????this;
*/
View getView();
/**
* ????????1.4.8?????6????STYLE_DEFAULT?STYLE_SCALE?STYLE_PIN?STYLE_FOLLOW_SCALE?STYLE_FOLLOW_PIN?STYLE_FOLLOW_CENTER;
*/
int getStyle();
/**
* ?????????????????STYLE_SCALE?STYLE_FOLLOW_SCALE?????????????0????????????????????????????;
*/
int getCustomHeight();
/**
* ??????;
*/
void onFingerUp(SmoothRefreshLayout layout, T indicator);
/**
* ????;
*/
void onReset(SmoothRefreshLayout layout);
/**
* ???????????;
*/
void onRefreshPrepare(SmoothRefreshLayout layout);
/**
* ????;
*/
void onRefreshBegin(SmoothRefreshLayout layout, T indicator);
/**
* ????;
*/
void onRefreshComplete(SmoothRefreshLayout layout,boolean isSuccessful);
/**
* ???????????????;
*/
void onRefreshPositionChanged(SmoothRefreshLayout layout, byte status, T indicator);
/**
* ?????????????????????????????????????;
* ?1.4.6?????;
*/
void onPureScrollPositionChanged(SmoothRefreshLayout layout, byte status, T indicator);
}
?????????
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);
}
}
);
mRefreshLayout.setHeaderView(header);
mRefreshLayout.setFooterView(footer);
- ?????Xml??,SmoothRefreshLayout??????View??????IRefreshView??????
???QQ??????
mRefreshLayout.setIndicatorOffsetCalculator(new IIndicator.IOffsetCalculator() {
@Override
public float calculate(@IIndicator.MovingStatus int status, int currentPos, float offset) {
if (status == IIndicator.MOVING_HEADER) {
if (offset < 0) {
//???????????QQ??????????????????????????offset
//???????????QQ????????????????????
return offset;
}
return (float) Math.pow(Math.pow(currentPos / 2, 1.28d) + offset, 1 / 1.28d) * 2 - currentPos;
}
else if (status == IIndicator.MOVING_FOOTER) {
if (offset > 0) {
//???????????QQ??????????????????????????offset
//???????????QQ????????????????????
return offset;
}
return -((float) Math.pow(Math.pow(currentPos / 2, 1.28d) - offset, 1 / 1.28d) * 2 - currentPos);
}
else {
if (offset > 0) {
return (float) Math.pow(offset, 1 / 1.28d) * 2;
}
else if (offset < 0) {
return -(float) Math.pow(-offset, 1 / 1.28d) * 2;
}
else {
return offset;
}
}
}
}
);
Xml??
SmoothRefreshLayout ????
?? | ?? | ?? |
sr_content | reference | ?????????ID |
sr_resistance | float | ????????????????: 1.65f ? |
sr_resistance_of_footer | float | ??Footer????????????: 1.65f ? |
sr_resistance_of_header | float | ??Header????????????: 1.65f ? |
sr_ratio_of_refresh_height_to_refresh | float | ???????????????????: 1.1f ? |
sr_ratio_of_header_height_to_refresh | float | ????????Header?????????: 1.1f ? |
sr_ratio_of_footer_height_to_refresh | float | ??????????Footer?????????: 1.1f ? |
sr_offset_ratio_to_keep_refresh_while_Loading | float | ?????????????????????: 1f ?,??????????????????????? |
sr_offset_ratio_to_keep_header_while_Loading | float | ??????????Header?????????: 1f ?,??????????????????????? |
sr_offset_ratio_to_keep_footer_while_Loading | float | ??????????Footer?????????: 1f ?,??????????????????????? |
sr_can_move_the_max_ratio_of_refresh_height | float | ??????????????????: 0f ???????? |
sr_can_move_the_max_ratio_of_header_height | float | ???????Header?????????: 0f ???????? |
sr_can_move_the_max_ratio_of_footer_height | float | ???????Footer?????????: 0f ???????? |
sr_duration_to_close_of_refresh | integer | ???????????????????: 500 ? |
sr_duration_to_close_of_header | integer | ????Header?????????????: 500 ? |
sr_duration_to_close_of_footer | integer | ????Footer?????????????: 500 ? |
sr_duration_of_back_to_keep_refresh_pos | integer | ???????????????????: 200 ? |
sr_duration_of_back_to_keep_header_pos | integer | ???????Header??????????: 200 ? |
sr_duration_of_back_to_keep_header_pos | integer | ???????Footer??????????: 200 ? |
sr_enable_pin_content | boolean | ?????????: false ? |
sr_enable_keep_refresh_view | boolean | ????????????????????????: true ? |
sr_enable_pull_to_refresh | boolean | ????,???????????????????????: false ? |
sr_enable_over_scroll | boolean | ???????: true ? |
sr_empty_layout | reference | ?????????????ID |
sr_error_layout | reference | ??????????????ID |
sr_custom_layout | reference | ???????????????ID |
sr_state | enum | ???? ???: STATE_CONTENT ? |
sr_enable_refresh | boolean | ?????????????: ture ? |
sr_enable_load_more | boolean | ?????????????: false ? |
sr_header_background_color | color | ??Header?????????? |
sr_footer_background_color | color | ??Footer?????????? |
TwoLevelSmoothRefreshLayout ????
?? | ?? | ?? |
sr_enable_two_level_refresh | boolean | ?????????????: true ? |
SmoothRefreshLayout??????View????
?? | ?? | ?? |
layout_gravity | flag | ??????????????(? targetView??refreshView) |
SmoothRefreshLayout java??????
?? | ?? | ?? |
setHeaderView | IRefreshView | ?????? |
setFooterView | IRefreshView | ?????? |
setContentView | int,View | ??????,??1:???????????,??2:????????? |
setState | int | ?????? |
setState | int,boolean | ??????,??1:????,??2:?????????? |
setDisableWhenAnotherDirectionMove | boolean | ??????????????????????ture???: false ? |
setEnableNextPtrAtOnce | boolean | ?????????? |
setOverScrollDurationRatio | float | ???????,??????????????????????????,???????? mMaxOverScrollDuration ?????: 0.5f ?. |
setMaxOverScrollDuration | int | ???????????????: 500 ? |
setMinOverScrollDuration | int | ???????????????: 150 ? |
setResistance | float | ????????????????: 1.65f ? |
setResistanceOfFooter | float | ??Footer????????????: 1.65f ? |
setResistanceOfHeader | float | ??Header????????????: 1.65f ? |
setRatioOfRefreshViewHeightToRefresh | float | ???????????????????: 1.1f ? |
setRatioOfHeaderHeightToRefresh | float | ????????Header?????????: 1.1f ? |
setRatioOfFooterHeightToRefresh | float | ??????????Footer?????????: 1.1f ? |
setOffsetRatioToKeepRefreshViewWhileLoading | float | ?????????????????????: 1f ?,??????????????????????? |
setOffsetRatioToKeepHeaderWhileLoading | float | ??????????Header?????????: 1f ?,??????????????????????? |
setOffsetRatioToKeepFooterWhileLoading | float | ??????????Footer?????????: 1f ?,??????????????????????? |
setCanMoveTheMaxRatioOfRefreshViewHeight | float | ??????????????????: 0f ???????? |
setCanMoveTheMaxRatioOfHeaderHeight | float | ???????Header?????????: 0f ???????? |
setCanMoveTheMaxRatioOfFooterHeight | float | ???????Footer?????????: 0f ???????? |
setDurationToClose | int | ???????????????????: 500 ? |
setDurationToCloseHeader | int | ????Header?????????????: 500 ? |
setDurationToCloseFooter | int | ????Footer?????????????: 500 ? |
setDurationOfBackToKeepRefreshViewPosition | integer | ???????????????????: 200 ? |
setDurationOfBackToKeepHeaderPosition | integer | ???????Header??????????: 200 ? |
setDurationOfBackToKeepFooterPosition | integer | ???????Footer??????????: 200 ? |
setEnablePinContentView | boolean | ?????????: false ? |
setEnabledPullToRefresh | boolean | ????,???????????????????????: false ? |
setEnableOverScroll | boolean | ???????: true ? |
setEnabledInterceptEventWhileLoading | boolean | ???????????????: false ? |
setEnableHeaderDrawerStyle | boolean | Header????,?Header????????????: false ? |
setEnableFooterDrawerStyle | boolean | Footer????,?Footer????????????: false ? |
setDisablePerformRefresh | boolean | ????Header?????: false ? |
setDisablePerformLoadMore | boolean | ????Footer?????: false ? |
setEnableLoadMoreNoMoreData | boolean | ??Footer???????????? true ??Frame??? setDisablePerformLoadMore ??? true ??????????????????????, ClassicFooter ???????????????: false ? |
isEnabledLoadMoreNoMoreDataNoNeedSpringBack | boolean | ??Footer????????????? |
setDisableRefresh | boolean | ??Header?????: false ? |
setDisableLoadMore | boolean | ??Footer?????: false ? |
setEnableKeepRefreshView | boolean | ????????????????????????: true ? |
setEnableScrollToBottomAutoLoadMore | boolean | ??????????: false ? |
setEnablePinRefreshViewWhileLoading | boolean | ????????????????????????????Material?????: false ?,???????? setEnablePinContentView ? setEnableKeepRefreshView 2?????????????? |
setSpringInterpolator | Interpolator | ?????????? |
setOverScrollInterpolator | Interpolator | ????????????? |
setEnableCheckFingerInsideAnotherDirectionView | boolean | ??????????????????????????????????????? setDisableWhenAnotherDirectionMove |
setEnableCompatLoadMoreScroll | boolean | ???????????????????: true ? |
setHeaderBackgroundColor | int | ??Header?????????????????Header??????????????????????????????????? |
setFooterBackgroundColor | int | ??Footer?????????????????Footer??????????????????????????????????? |
SmoothRefreshLayout ??
?? | ?? | ?? |
setOnRefreshListener | T extends OnRefreshListener | ?????????? |
setOnStateChangedListener | OnStateChangedListener | ???????? |
setChangeStateAnimatorCreator | IChangeStateAnimatorCreator | ??????????????? |
addOnUIPositionChangedListener | OnUIPositionChangedListener | ????????????? |
removeOnUIPositionChangedListener | OnUIPositionChangedListener | ????????????? |
setOnLoadMoreScrollCallback | OnLoadMoreScrollCallback | ??Footer?????????????? |
setOnPerformAutoLoadMoreCallBack | OnPerformAutoLoadMoreCallBack | ????????????????????? canAutoLoadMore() ???? true ?????????? |
setOnChildNotYetInEdgeCannotMoveHeaderCallBack | OnChildNotYetInEdgeCannotMoveHeaderCallBack | ???????????????????SmoothRefreshLayout?? isChildNotYetInEdgeCannotMoveHeader() ??? |
setOnChildNotYetInEdgeCannotMoveFooterCallBack | OnChildNotYetInEdgeCannotMoveFooterCallBack | ???????????????????SmoothRefreshLayout?? isChildNotYetInEdgeCannotMoveFooter() ??? |
setOnHookHeaderRefreshCompleteCallback | OnHookUIRefreshCompleteCallBack | ??Header?????Hook???????????? |
setOnHookFooterRefreshCompleteCallback | OnHookUIRefreshCompleteCallBack | ??Footer?????Hook???????????? |
setOnFingerInsideAnotherDirectionViewCallback | OnFingerInsideAnotherDirectionViewCallback | ????????????????????????????????????????? |
SmoothRefreshLayout ??
?? | ?? | ?? |
debug?????? | boolean | Debug?? |
setDefaultCreator?????? | IRefreshViewCreator | ?????????,????????????????????????????????????? |
refreshComplete | ?? | ????,?????????????? |
refreshComplete | boolean | ????,??:?????????????? |
refreshComplete | boolean,long | ????,??1:??????????????,??2:??????????????????????????????????????????????????? |
refreshComplete | long | ????,??????????????,??:??????????????????????????????????????????????????? |
setLoadingMinTime | long | ?????????????????(??: 500 ),??:??? |
autoRefresh | ?? | ????Header??,??????????????Header???? |
autoRefresh | boolean | ????Header??,??:??????????,??????Header???? |
autoRefresh | boolean,boolean | ????Header??,??1:??????????,??2:???????Header???? |
autoLoadMore | ?? | ????Footer??,??????????????Footer???? |
autoLoadMore | boolean | ????Footer??,??:??????????,??????Footer???? |
autoLoadMore | boolean,boolean | ????Footer??,??1:??????????,??2:???????Footer???? |
setLoadMoreScrollTargetView | View | ??Footer???,???????????,???SmoothRefreshLayout????CoordinatorLayout,CoordinatorLayout??AppbarLayout?RecyclerView????????????????RecyclerView???CoordinatorLayout,????RecyclerView?TargetView?? |
TwoLevelSmoothRefreshLayout java??????
?? | ?? | ?? |
setRatioOfHeaderHeightToHintTwoLevelRefresh | float | ???????????????Header?????? |
setRatioOfHeaderHeightToTwoLevelRefresh | float | ?????????????Header?????? |
setOffsetRatioToKeepTwoLevelHeaderWhileLoading | float | ????????????Header?????????: 1f ? |
setDisableTwoLevelRefresh | boolean | ?????????????: false ? |
setDurationOfBackToKeepTwoLevelHeaderViewPosition | int | ???????????Header??????????: 500 ? |
setDurationToCloseTwoLevelHeader | int | ??????Header?????????????????: 500 ? |
TwoLevelSmoothRefreshLayout ??
?? | ?? | ?? |
autoTwoLevelRefreshHint | ?? | ???????????????????????????? |
autoTwoLevelRefreshHint | int | ??????????????????????????????:?????? |
autoTwoLevelRefreshHint | boolean | ????????????????????????????????:????????? |
autoTwoLevelRefreshHint | boolean,int | ??????????,??1:????????????2:?????? |
autoTwoLevelRefreshHint | boolean,int,boolean | ??????????,??1:????????????2:?????????3:???????????????????????????????????????????? |
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.