android - API 21 中的 SwipeRefreshLayout

标签 android swiperefreshlayout

我之前使用的是 API 19,并且在我的许多 fragment 中都使用了 SwipeRefreshLayout。当我之前第一次加载内容时,我使用的是 setRefreshing(true); 并且能够加载内容并且工作正常。

我注意到在 Android 5.0 中,Google 正在使用循环进度 View 。当我调用 setRefreshing(true); 现在它根本没有效果。无论如何以编程方式显示新的微调器?我已经深入研究了这一点,但无法以编程方式显示它。我已经阅读了以下内容:

http://developer.android.com/tools/support-library/index.html

https://yassirh.com/2014/05/how-to-use-swiperefreshlayout-the-right-way/

SwipeRefreshLayout doesn't show any indicator of refreshing

基本上,它在第一次尝试时没有显示刷新的迹象。

最佳答案

而不是直接设置

getSwipeRefreshLayout().setRefreshing(true);

您可以稍后在 UI 线程上延迟它

getSwipeRefreshLayout().post(new Runnable() {
    @Override public void run() {
        getSwipeRefreshLayout().setRefreshing(true);
    }
});

这对我来说非常适合开始在 onCreateView 中加载,如果在 LoaderManager.LoaderCallbacks 中完成。

我没有看到进度条不小心卡住了(因为数据加载太快了),但是如果您怀疑加载可能会过早返回(错误?)值得做同样的发布

getSwipeRefreshLayout().setRefreshing(false);

这样两个 post 肯定会一个接一个地出现,从而形成一个绝对隐藏的进度 View 。

关于android - API 21 中的 SwipeRefreshLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26601175/

相关文章:

android - 如何使用 viewflipper 将变量传递给下一个 View

android - 新版本的 SwipeRefreshLayout 导致 View 绘制错误

android - SwipeRefreshLayout 拦截与 ViewPager

android - 滑动刷新仅在用户滑动时调用,而不是在用户到达列表顶部时调用

android - Android webView中 `webView.getSolidColor();`有什么用?

java - 处理程序真正将其消息发布到哪里?

android - 进度条在 AsyncTask 中不起作用

java - 如何以及为什么不在 URLConnection (DownloadFile) 上运行 "timeout"?

android - 在 SwipeRefreshLayout 上设置刷新( bool 值)时偶尔会出现 NullPointerExceptions

android - ActionBar 后面的 SwipeRefreshLayout