首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android支持v4 SwipeRefreshLayout空视图问题

Android支持v4 SwipeRefreshLayout空视图问题
EN

Stack Overflow用户
提问于 2014-04-09 18:01:45
回答 5查看 17K关注 0票数 17

为SwipeRefresh布局的唯一子级listview设置空视图后,SwipeRefresh不起作用。如何解决这个问题?

EN

回答 5

Stack Overflow用户

发布于 2014-05-15 19:07:54

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

代码语言:javascript
复制
    <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>

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

代码语言:javascript
复制
_listView.setEmptyView(findViewById(android.R.id.empty));

就这样。

票数 22
EN

Stack Overflow用户

发布于 2014-12-02 18:26:00

下面是我是如何做到这一点的(可能不是很优雅的解决方案)

代码语言:javascript
复制
private void createEmptyView() {
    ViewGroup parent = (ViewGroup) listView.getParent();
    emptyView = (TextView) getLayoutInflater(null)
            .inflate(R.layout.view_empty, parent, false);
    parent.addView(emptyView);
    listView.setEmptyView(emptyView);
}

public class FrameSwipeRefreshLayout extends SwipeRefreshLayout {

    private ViewGroup listView;
    public void setListView(ViewGroup list) {
        listView = list;
    }

    @Override
    public boolean canChildScrollUp() {
        if (listView != null) {
            View child = listView.getChildAt(0);
            return child != null && child.getTop() != 0;
        }
        return super.canChildScrollUp();
    }
}

空布局

代码语言:javascript
复制
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="center_horizontal"
      android:clickable="true" />

列表布局

代码语言:javascript
复制
    <FrameSwipeRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            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"
            />
        </FrameLayout>
    </FrameSwipeRefreshLayout>
票数 2
EN

Stack Overflow用户

发布于 2014-04-12 10:21:27

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

Android - SwipeRefreshLayout with empty textview

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22959118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档