@OnClick(R.id.float_imageButton) void onClickFloatIv() { mWaterFallRcv.smoothScrollToPosition(0); }
private void setWaterFallRcv() { // 设置头部或底部的操作应该在setAdapter之前 mWaterFallRcv.addHeaderView(mHeaderBlock.mHeaderLl); mWaterFallRcv.addFooterView(mFooterBlock.mFooterLl); ExStaggeredGridLayoutManager staggeredGridLayoutManager = new ExStaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); // GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2); // LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getBaseContext(), // LinearLayoutManager.VERTICAL, true);// 可替换 mWaterFallRcv.setLayoutManager(staggeredGridLayoutManager); // 添加分割线 mWaterFallRcv.addItemDecoration(new DividerGridItemDecoration(this)); // mWaterFallRcv.addItemDecoration(new DividerItemDecoration(this, // DividerItemDecoration.VERTICAL_LIST));//可替换 List<ObjectListEntity> mData = new ArrayList<>(); // 先放一个空的list mCartoonAdapter.setAdapter(mData); // 不显示滚动到顶部/底部的阴影(减少绘制) mWaterFallRcv.setOverScrollMode(View.OVER_SCROLL_NEVER); // waterFallRcv.setClipToPadding(true); mWaterFallRcv.setAdapter(mCartoonAdapter.mQuickRcvAdapter); // Solve IndexOutOfBoundsException exception // 解决上下拉刷新时还可以进行滑动的问题 mWaterFallRcv.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (isLoadingData) { return true; } else { return false; } } }); /** 监听滚动事件 */ mWaterFallRcv.addOnScrollListener( new OnRecyclerViewScrollListener() { @Override public void onScrollUp() { // Log.d(TAG, "onScrollUp"); hideViews(); } @Override public void onScrollDown() { // Log.d(TAG, "onScrollDown"); showViews(); } @Override public void onBottom() { // Log.d(TAG, "on bottom"); Toastor.showSingletonToast(HeaderOrFooterActivity.this, "bottom"); // 到底部自动加载 if (!isLoadingData) { isLoadingData = true; mDataManager.loadOldData(HeaderOrFooterActivity.this); mFooterBlock.mFooterLl.setVisibility(View.VISIBLE); } } @Override public void onMoved(int distanceX, int distanceY) { // LogUtils.d("distance X = " + distanceX + "distance Y = " + distanceY); setToolbarBgByScrollDistance(distanceY); } }); }