Android支持v4 SwipeRefreshLayout空视图问题

Din*_*esh 16 android android-layout swiperefreshlayout

为listview设置空视图后,SwipeRefresh无效,这是SwipeRefresh布局的唯一子项.如何解决这个问题?

nit*_*oel 22

这是解决方案:您可以简单地使用此视图层次结构:

    <FrameLayout ...>

        <android.support.v4.widget.SwipeRefreshLayout ...>

            <ListView
                android:id="@android:id/list" ... />
        </android.support.v4.widget.SwipeRefreshLayout>

        <TextView
            android:id="@android:id/empty" ...
            android:text="@string/empty_list"/>
    </FrameLayout>
Run Code Online (Sandbox Code Playgroud)

然后,在代码中,您只需调用:

_listView.setEmptyView(findViewById(android.R.id.empty));
Run Code Online (Sandbox Code Playgroud)

而已.

  • 很好,赞成.但是我还有一个问题,那就是我无法刷掉这个空视图来刷新.是不是..我可以得到这个解决方案..在此先感谢.@nitesh (4认同)
  • 如果你要接受其他人的回答并使用它作为你的答案至少给他们信用:http://stackoverflow.com/a/23424655/893130 (3认同)

avb*_*avb 5

我也遇到了这个问题,并通过使用下面的布局在活动中没有任何额外代码的情况下解决了这个问题。

如果您使用 aListActivityListFragment它会为您处理显示/隐藏空视图,并且使用此布局结构刷新空列表也可以工作。

不需要 hack,一切都在 . 中SwipeRefreshLayout,因为它应该是。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Refresher"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:divider="@null" />
        <ScrollView
            android:id="@android:id/empty"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <TextView
                android:text="Geen formulieren gevonden"
                style="@style/text.EmptyView" />
        </ScrollView>
    </LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)

希望这对你有帮助。如果是这样,请不要忘记接受答案。

注意:这是我对这个问题的回答的重复,但那个问题几乎是这个问题的重复...... :)

更新
如果 SwipeRefreshLayout 过早激活,您可以使用以下方法实现 ListView.OnScroll:

_refresher.Enabled = e.FirstVisibleItem == 0;
Run Code Online (Sandbox Code Playgroud)

这将禁用刷新,直到您滚动到顶部。这仅在使用 ListView 时才需要,新的 RecyclerView 按预期工作。


huf*_*g03 1

这个问题你可以看看。我发布了一个解决方案。

Android - 带有空文本视图的 SwipeRefreshLayout