用到的布局:SwiperRefreshLayout,AppBarLayout,ToolBar,CollapsingToolbarLayout,CoordinatorLayout
布局
//自定义的ToolBar //可滑动的布局,可以换成ListView之类的
Java:
SwipeRefreshLayout mRefreshLayout;AppBarLayout mAppBarLayout;mRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.deduction_record_swipefreshlayout); mRefreshLayout.setOnRefreshListener(this); mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout); //主要是解决header固定之后会引起刷新,可去除看下效果 mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { Log.i("测试===","verticalOffset:"+verticalOffset); //顶部可隐藏布局的滑动(verticalOffset类似Y坐标) if (verticalOffset == 0){ mRefreshLayout.setEnabled(true); }else{ mRefreshLayout.setEnabled(false); } } });