我在我的 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/