@@ -158,69 +158,30 @@ private void initView() {
158
158
filterViewPosition = smoothListView .getHeaderViewsCount () - 1 ;
159
159
}
160
160
161
- private void initListener () {
162
- smoothListView .setRefreshEnable (true );
163
- smoothListView .setLoadMoreEnable (true );
164
- smoothListView .setSmoothListViewListener (this );
165
- smoothListView .setOnScrollListener (new SmoothListView .OnSmoothScrollListener () {
166
- @ Override
167
- public void onSmoothScrolling (View view ) {}
168
-
169
- @ Override
170
- public void onScrollStateChanged (AbsListView view , int scrollState ) {}
161
+ private boolean isScrollIdle = true ;
162
+ View headerAdView ;
163
+ View headerFilterView ;
171
164
165
+ private void initListener () {
166
+ // 关于
167
+ flActionMore .setOnClickListener (new View .OnClickListener () {
172
168
@ Override
173
- public void onScroll (AbsListView view , int firstVisibleItem , int visibleItemCount , int totalItemCount ) {
174
- View adView = smoothListView .getChildAt (1 - firstVisibleItem );
175
- if (adView != null ) {
176
- adViewTopSpace = DensityUtil .px2dip (mContext , adView .getTop ());
177
- adViewHeight = DensityUtil .px2dip (mContext , adView .getHeight ());
178
- }
179
-
180
- View filterView = smoothListView .getChildAt (filterViewPosition - firstVisibleItem );
181
- if (filterView != null ) {
182
- filterViewTopSpace = DensityUtil .px2dip (mContext , filterView .getTop ());
183
- }
184
-
185
- // 处理筛选是否吸附在顶部
186
- if (filterViewTopSpace > titleViewHeight ) {
187
- isStickyTop = false ; // 没有吸附在顶部
188
- fvTopFilter .setVisibility (View .INVISIBLE );
189
- } else {
190
- isStickyTop = true ; // 吸附在顶部
191
- fvTopFilter .setVisibility (View .VISIBLE );
192
- }
193
-
194
- if (firstVisibleItem > filterViewPosition ) {
195
- isStickyTop = true ;
196
- fvTopFilter .setVisibility (View .VISIBLE );
197
- }
198
-
199
- if (isSmooth && isStickyTop ) {
200
- isSmooth = false ;
201
- fvTopFilter .showFilterLayout (filterPosition );
202
- }
203
-
204
- fvTopFilter .setStickyTop (isStickyTop );
205
-
206
- // 处理标题栏颜色渐变
207
- handleTitleBarColorEvaluate ();
169
+ public void onClick (View v ) {
170
+ startActivity (new Intent (mActivity , AboutActivity .class ));
208
171
}
209
172
});
210
173
211
- // (真正的 )筛选视图点击
174
+ // (假的ListView头部展示的 )筛选视图点击
212
175
headerFilterViewView .setOnFilterClickListener (new HeaderFilterViewView .OnFilterClickListener () {
213
176
@ Override
214
177
public void onFilterClick (int position ) {
215
- if (!isStickyTop ) {
216
- filterPosition = position ;
217
- isSmooth = true ;
218
- smoothListView .smoothScrollToPositionFromTop (filterViewPosition , DensityUtil .dip2px (mContext , titleViewHeight ));
219
- }
178
+ filterPosition = position ;
179
+ isSmooth = true ;
180
+ smoothListView .smoothScrollToPositionFromTop (filterViewPosition , DensityUtil .dip2px (mContext , titleViewHeight ));
220
181
}
221
182
});
222
183
223
- // (假的ListView头部展示的 )筛选视图点击
184
+ // (真正的 )筛选视图点击
224
185
fvTopFilter .setOnFilterClickListener (new FilterView .OnFilterClickListener () {
225
186
@ Override
226
187
public void onFilterClick (int position ) {
@@ -234,14 +195,6 @@ public void onFilterClick(int position) {
234
195
}
235
196
});
236
197
237
- // 关于
238
- flActionMore .setOnClickListener (new View .OnClickListener () {
239
- @ Override
240
- public void onClick (View v ) {
241
- startActivity (new Intent (mActivity , AboutActivity .class ));
242
- }
243
- });
244
-
245
198
// 分类Item点击
246
199
fvTopFilter .setOnItemCategoryClickListener (new FilterView .OnItemCategoryClickListener () {
247
200
@ Override
@@ -265,6 +218,65 @@ public void onItemFilterClick(FilterEntity entity) {
265
218
fillAdapter (ModelUtil .getFilterTravelingData (entity ));
266
219
}
267
220
});
221
+
222
+ smoothListView .setRefreshEnable (true );
223
+ smoothListView .setLoadMoreEnable (true );
224
+ smoothListView .setSmoothListViewListener (this );
225
+ smoothListView .setOnScrollListener (new SmoothListView .OnSmoothScrollListener () {
226
+ @ Override
227
+ public void onSmoothScrolling (View view ) {}
228
+
229
+ @ Override
230
+ public void onScrollStateChanged (AbsListView view , int scrollState ) {
231
+ isScrollIdle = (scrollState == AbsListView .OnScrollListener .SCROLL_STATE_IDLE );
232
+ }
233
+
234
+ @ Override
235
+ public void onScroll (AbsListView view , int firstVisibleItem , int visibleItemCount , int totalItemCount ) {
236
+ if (isScrollIdle && adViewTopSpace < 0 ) return ;
237
+
238
+ // 获取广告头部View、自身的高度、距离顶部的高度
239
+ if (headerAdView == null ) {
240
+ headerAdView = smoothListView .getChildAt (1 -firstVisibleItem );
241
+ }
242
+ if (headerAdView != null ) {
243
+ adViewTopSpace = DensityUtil .px2dip (mContext , headerAdView .getTop ());
244
+ adViewHeight = DensityUtil .px2dip (mContext , headerAdView .getHeight ());
245
+ }
246
+
247
+ // 获取筛选View、距离顶部的高度
248
+ if (headerFilterView == null ) {
249
+ headerFilterView = smoothListView .getChildAt (filterViewPosition - firstVisibleItem );
250
+ }
251
+ if (headerFilterView != null ) {
252
+ filterViewTopSpace = DensityUtil .px2dip (mContext , headerFilterView .getTop ());
253
+ }
254
+
255
+ // 处理筛选是否吸附在顶部
256
+ if (filterViewTopSpace > titleViewHeight ) {
257
+ isStickyTop = false ; // 没有吸附在顶部
258
+ fvTopFilter .setVisibility (View .INVISIBLE );
259
+ } else {
260
+ isStickyTop = true ; // 吸附在顶部
261
+ fvTopFilter .setVisibility (View .VISIBLE );
262
+ }
263
+
264
+ if (firstVisibleItem > filterViewPosition ) {
265
+ isStickyTop = true ;
266
+ fvTopFilter .setVisibility (View .VISIBLE );
267
+ }
268
+
269
+ if (isSmooth && isStickyTop ) {
270
+ isSmooth = false ;
271
+ fvTopFilter .showFilterLayout (filterPosition );
272
+ }
273
+
274
+ fvTopFilter .setStickyTop (isStickyTop );
275
+
276
+ // 处理标题栏颜色渐变
277
+ handleTitleBarColorEvaluate ();
278
+ }
279
+ });
268
280
}
269
281
270
282
// 填充数据
@@ -283,23 +295,26 @@ private void fillAdapter(List<TravelingEntity> list) {
283
295
private void handleTitleBarColorEvaluate () {
284
296
float fraction ;
285
297
if (adViewTopSpace > 0 ) {
286
- fraction = adViewTopSpace * 1f / 60 ;
287
- rlBar .setAlpha (1.0f - fraction );
298
+ fraction = 1f - adViewTopSpace * 1f / 60 ;
299
+ if (fraction < 0f ) fraction = 0f ;
300
+ rlBar .setAlpha (fraction );
288
301
return ;
289
302
}
290
303
291
304
float space = Math .abs (adViewTopSpace ) * 1f ;
292
305
fraction = space / (adViewHeight - titleViewHeight );
293
- rlBar .setAlpha (1.0f );
306
+ if (fraction < 0f ) fraction = 0f ;
307
+ if (fraction > 1f ) fraction = 1f ;
308
+ rlBar .setAlpha (1f );
294
309
295
- if (fraction > 1.0f || isStickyTop ) {
310
+ if (fraction >= 1f || isStickyTop ) {
296
311
isStickyTop = true ;
297
312
viewTitleBg .setAlpha (0f );
298
313
viewActionMoreBg .setAlpha (0f );
299
314
rlBar .setBackgroundColor (mContext .getResources ().getColor (R .color .orange ));
300
315
} else {
301
- viewTitleBg .setAlpha (1.0f - fraction );
302
- viewActionMoreBg .setAlpha (1.0f - fraction );
316
+ viewTitleBg .setAlpha (1f - fraction );
317
+ viewActionMoreBg .setAlpha (1f - fraction );
303
318
rlBar .setBackgroundColor (ColorUtil .getNewColorByStartEndColor (mContext , fraction , R .color .transparent , R .color .orange ));
304
319
}
305
320
}
0 commit comments