如何禁用“拉刷新”操作并只使用指示器?

我使用 SwipeRefreshLayout为我的项目启用了“ pull to refresh”。

当我向下移动时,出现加载指示器(材料设计风格)。我知道,它必须这样工作,但我想禁用这个功能,并开始刷新通过点击一些按钮,并使用 SwipeRefreshLayout加载指示器。

我该怎么做?

56522 次浏览

From the documentation:

If an activity wishes to show just the progress animation, it should call setRefreshing(true). To disable the gesture and progress animation, call setEnabled(false) on the view.

So to show the animation:

swiperefreshLayout.setEnabled(true);
swiperefreshLayout.setRefreshing(true);

And to hide the animation:

swiperefreshLayout.setRefreshing(false);
swiperefreshLayout.setEnabled(false);

You don't have to always enable and disable. Just disable once when the view is created and then use setRefreshing.