Bet*_*ang 1 android swiperefreshlayout android-toolbar android-appbarlayout
我SwipeRefreshLayout用作布局的根元素,因为我需要刷新屏幕上的所有内容。布局如下:
<SwipeRefreshLayout>
<CoordinatorLayout>
<ViewPager />
<AppBarLayout>
<Toolbar />
<FrameLayout>
...
</FrameLayout>
<TabLayout />
</CoordinatorLayout>
</SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
当我在布局上向下滑动时,刷新圈SwipeRefreshLayout出现在屏幕顶部,位于Toolbar. 所以我使用SwipeRefreshLayout#setProgressViewOffset让圆圈从工具栏高度的偏移量开始,但是当刷新完成时,圆圈会在消失之前奇怪地挂在工具栏上一会儿:截图
如何在工具栏下制作刷新圆圈?
似乎您想要实现一个共面指示器,如Material Design Guidelines 中所述。为此,您应该使用setProgressViewEndTarget()或setProgressViewOffset()方法:
// This method will offset the end of the indicator animation
int target = getResources().getDimensionPixelSize(R.dimen.indicator_end_target);
mSwipeRefreshLayout.setProgressViewEndTarget(true, target);
// This method allows you to set both the start and end values for the indicator animation
int start = getResources().getDimensionPixelSize(R.dimen.indicator_start);
int end = getResources().getDimensionPixelSize(R.dimen.indicator_end);
mSwipeRefreshLayout.setProgressViewOffset(true, start, end);
Run Code Online (Sandbox Code Playgroud)
通过true在这些方法中的每一个中将第一个参数设置为,指示器将在它进入视图时对其比例进行动画处理,而不是仅仅被包含视图的边缘剪裁。