我已经实现SwipeRefreshLayout
了我的应用程序,但它只能容纳一个应该是listview的直接子项.我试图找出如何将空文本视图添加到以下工作XML文件:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/listViewConversation"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1dp" />
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
将其包装在线性/相对布局中会使其失灵,因为当您想要向下滑动列表视图时,列表视图将始终更新.我能想到的一种方法是以编程方式进行此操作,但我想这不是最好的选择.
您可以使用本教程学习如何实现它:滑动以刷新GUIDE
所以基本上它一切正常,但我想添加一个空视图,当listview为空时显示一条消息.
可能吗 ??正如标题所说
向下滑动以刷新布局,但坚持布局不要沿着滑动gusture向下移动
谢谢 - 我正在使用SwipeRefreshLayout
我的android项目包括一个recyclerView,其中包含一个cardViews列表,并且在这个recyclerView的顶部还有一个swipeRefreshLayout。当我向下滚动列表并拉起那些 cardViews 时,我只想禁用 swipeRefreshLayout。换句话说,当 RecyclerView 不在第一项上时,如果用户想滚动回第一项,它一定不能显示 swipeRefreshLayout。
我onScrollStateChanged
在谷歌上搜索了很多关于这个问题的解决方案,并且有一些解决方案可以覆盖方法,但它们的行为不是很流畅,并且在某些情况下仍然启用 swipeRefreshLayout。
编辑 1: 以下链接包括我上面提到的一些解决方案:
https://gist.github.com/NikolaDespotoski/1a6bb83dbae133f67812
这是我的 xml 布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:choiceMode="none"
android:focusable="false"
android:listSelector="@android:color/darker_gray" />
<ImageView
android:id="@+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" />
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
编辑 2: 今天我意识到我的问题是由于同时实施 Tabs 和 swipeRefreshLayout 而发生的。刷新包含 RecyclerView 的 Fragment 的数据,用户必须将页面拖到底部,反之,要在选项卡之间切换,用户必须向右或向左拖动屏幕。由于这种触摸手势,滚动我的列表时会出现一些错误和滞后。请帮我解决这个问题。非常感谢。
android swiperefreshlayout material-design android-recyclerview
android ×3