@@ -98,47 +98,75 @@ Please rest assured that I have divided it into three packages, when used to ref |
98 | 98 |
|
99 | 99 | ## Usage |
100 | 100 | #### 1.Add a gradle dependency. |
| 101 | + |
| 102 | +V 2.x changed the package name relative to 1.x, such as `com.scwang.smartrefresh` to `com.scwang.smart.refresh`. |
| 103 | +But the main change is to subcontract SmartRefreshLayout to reduce unnecessary dependencies and avoid code redundancy. |
| 104 | +However, there is no subcontracting to SmartRefreshHeader. |
| 105 | +There are more than ten headers in it. |
| 106 | +It is recommended that you copy the source code into the project whenever you need to use it. |
| 107 | + |
101 | 108 | ``` |
102 | | -implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-beta-1' |
103 | | -implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-beta-1'//If you use the special Header |
104 | | -implementation 'com.android.support:appcompat-v7:25.3.1' |
| 109 | +// Note: There will be no default Header and Footer after subcontracting. It needs to be added manually! |
| 110 | +implementation 'com.scwang.smart.refresh-layout-kernel:2.0.0-alpha-1' //core |
| 111 | +implementation 'com.scwang.smart.refresh-header-classics:2.0.0-alpha-1' //ClassicsHeader |
| 112 | +implementation 'com.scwang.smart.refresh-header-radar:2.0.0-alpha-1' //BezierRadarHeader |
| 113 | +implementation 'com.scwang.smart.refresh-header-falsify:2.0.0-alpha-1' //FalsifyHeader |
| 114 | +implementation 'com.scwang.smart.refresh-header-material:2.0.0-alpha-1' //MaterialHeader |
| 115 | +implementation 'com.scwang.smart.refresh-header-two-level:2.0.0-alpha-1' //TwoLevelHeader |
| 116 | +implementation 'com.scwang.smart.refresh-footer-ball:2.0.0-alpha-1' //BallPulseFooter |
| 117 | +implementation 'com.scwang.smart.refresh-footer-classics:2.0.0-alpha-1' //ClassicsFooter |
| 118 | +
|
| 119 | +// The package name of `com.scwang.smartrefresh` is retained, but not subcontracted. |
| 120 | +implementation 'com.scwang.smartrefresh:SmartRefreshHeader:2.0.0-alpha-1' //Headers |
| 121 | +implementation 'com.scwang.smartrefresh:SmartRefreshFooter:2.0.0-alpha-1' //Footers |
| 122 | +implementation 'com.scwang.smartrefresh:SmartRefreshLayout:2.0.0-alpha-1' //core、 default Header and Footer |
105 | 123 |
|
106 | | -//androidx version |
107 | | -implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-andx-16' |
108 | | -implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-andx-16' |
109 | | -implementation 'androidx.legacy:legacy-support-v4:1.0.0' |
| 124 | +``` |
110 | 125 |
|
| 126 | +If you use AndroidX, add it to gradle.properties |
| 127 | + |
| 128 | +``` |
| 129 | +android.useAndroidX=true |
| 130 | +android.enableJetifier=true |
111 | 131 | ``` |
112 | 132 |
|
113 | 133 | #### 2.Add SmartRefreshLayout in the layout xml. |
114 | 134 | ```xml |
115 | 135 | <?xml version="1.0" encoding="utf-8"?> |
116 | | -<com.scwang.smartrefresh.layout.SmartRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 136 | +<com.scwang.smart.refresh.layout.SmartRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" |
117 | 137 | android:id="@+id/refreshLayout" |
118 | 138 | android:layout_width="match_parent" |
119 | 139 | android:layout_height="match_parent"> |
| 140 | + <com.scwang.smart.refresh.header.ClassicsHeader |
| 141 | + android:layout_width="match_parent" |
| 142 | + android:layout_height="wrap_content"/> |
120 | 143 | <android.support.v7.widget.RecyclerView |
121 | 144 | android:id="@+id/recyclerView" |
122 | 145 | android:layout_width="match_parent" |
123 | 146 | android:layout_height="match_parent" |
124 | 147 | android:overScrollMode="never" |
125 | 148 | android:background="#fff" /> |
126 | | -</com.scwang.smartrefresh.layout.SmartRefreshLayout> |
| 149 | + <com.scwang.smart.refresh.footer.ClassicsFooter |
| 150 | + android:layout_width="match_parent" |
| 151 | + android:layout_height="wrap_content"/> |
| 152 | +</com.scwang.smart.refresh.layout.SmartRefreshLayout> |
127 | 153 | ``` |
128 | 154 |
|
129 | 155 | #### 3.Coding in the Activity or Fragment. |
130 | 156 | ```java |
131 | 157 | RefreshLayout refreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout); |
| 158 | +refreshLayout.setRefreshHeader(new ClassicsHeader(this)); |
| 159 | +refreshLayout.setRefreshFooter(new ClassicsFooter(this)); |
132 | 160 | refreshLayout.setOnRefreshListener(new OnRefreshListener() { |
133 | 161 | @Override |
134 | 162 | public void onRefresh(RefreshLayout refreshlayout) { |
135 | | - refreshlayout.finishRefresh(2000); |
| 163 | + refreshlayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败 |
136 | 164 | } |
137 | 165 | }); |
138 | 166 | refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() { |
139 | 167 | @Override |
140 | 168 | public void onLoadMore(RefreshLayout refreshlayout) { |
141 | | - refreshlayout.finishLoadMore(2000); |
| 169 | + refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败 |
142 | 170 | } |
143 | 171 | }); |
144 | 172 | ``` |
@@ -171,7 +199,7 @@ Note: this method is the lowest priority. |
171 | 199 |
|
172 | 200 | #### 2.Specified in the XML layout file |
173 | 201 | ```xml |
174 | | -<com.scwang.smartrefresh.layout.SmartRefreshLayout |
| 202 | +<com.scwang.smart.refresh.layout.SmartRefreshLayout |
175 | 203 | xmlns:app="http://schemas.android.com/apk/res-auto" |
176 | 204 | android:id="@+id/refreshLayout" |
177 | 205 | android:layout_width="match_parent" |
@@ -182,7 +210,7 @@ Note: this method is the lowest priority. |
182 | 210 | app:srlEnablePreviewInEditMode="true"> |
183 | 211 | <!--srlAccentColor and srlPrimaryColor, Will change the Header and Footer theme colors--> |
184 | 212 | <!--srlEnablePreviewInEditMode, Can open and close the preview function--> |
185 | | - <com.scwang.smartrefresh.layout.header.ClassicsHeader |
| 213 | + <com.scwang.smart.refresh.header.ClassicsHeader |
186 | 214 | android:layout_width="match_parent" |
187 | 215 | android:layout_height="wrap_content"/> |
188 | 216 | <TextView |
@@ -191,10 +219,10 @@ Note: this method is the lowest priority. |
191 | 219 | android:padding="@dimen/dimenPaddingCommon" |
192 | 220 | android:background="@android:color/white" |
193 | 221 | android:text="@string/description_define_in_xml"/> |
194 | | - <com.scwang.smartrefresh.layout.footer.ClassicsFooter |
| 222 | + <com.scwang.smart.refresh.footer.ClassicsFooter |
195 | 223 | android:layout_width="match_parent" |
196 | 224 | android:layout_height="wrap_content"/> |
197 | | -</com.scwang.smartrefresh.layout.SmartRefreshLayout> |
| 225 | +</com.scwang.smart.refresh.layout.SmartRefreshLayout> |
198 | 226 | ``` |
199 | 227 |
|
200 | 228 | Note: this method of priority is medium。When using this method, the Android Studio will have preview effect, the following figure: |
|