android - 如何让 SwipeRefreshLayout 在我抬起手指之前不触发,并显示 "swipe to refresh text"

标签 android

我在我的 ListView 上实现了一个 SwipeRefreshLayout,它可以正常工作,但不是我想要的。

首先,刷新在我抬起手指之前触发,这感觉不对,因为它会将内容移回顶部,即使我的手指仍处于向下滑动的位置。此外,触发距离非常短,并且由于某种原因,文档中的 setDistanceToTriggerSync 对我不可用。

其次,当我的 ListView 被下拉时,我希望在间隙中显示某种 View ,例如告诉用户“向下滑动以刷新”的文本或动画(例如快速聊天)。我如何设置这个 View

这是我的

<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dashboardRootLayout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"

>

    <ListView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/lvDashboard"
        android:background="#ffffff"
        />

最佳答案

为什么 setDistanceToTriggerSync 不可用?

无论如何,SwipeRefreshLayout 的默认行为没有那个额外的 View ,它只有一个特殊的进度条和一个用于刷新和显示或不显示刷新进度的监听器。它还可以使用刷新消息更改操作栏的外观。

可能的解决方案:

如果你想要那个特殊的 View ,我的头顶上我可以考虑让列表通过动画向下移动并创建或放置 VISIBLE 你想要显示在 SwipeRefreshLayout 顶部的 View 。

    SwipeRefreshLayout swipeRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.dashboardRootLayout);
    swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener()
      {
        @Override
        public void onRefresh()
          {
          // do animation
          // set the view you want to show VISIBLE
          }
      });

您实际上可以在没有 SwipeRefreshLayout 的情况下自己实现所有这些,因为您不想要默认行为。

关于android - 如何让 SwipeRefreshLayout 在我抬起手指之前不触发,并显示 "swipe to refresh text",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27575215/

相关文章:

android - iOS/Android Phonegap - 智能手机纵向,平板电脑横向

java - 如何为字符串的数字和字符设置不同的颜色和大小

java - Android NDK 可以将 Windows dll 包含到 Android 共享库中吗?

android - 选择表的主键的最佳做法是什么

android - 无法访问 ViewStub'child

android - 在后台更新位置?

java - 有没有办法在Java中获取字符串的字节大小?

android - 如何更改 BottomSheetDialog 中的透明背景?

java - ANT Build - 签名 APK 签名问题

android - 搜索栏,我可以用 2 个拇指更改最小最大值