【问题标题】:How to set Empty view in android.support.v4.widget.SwipeRefreshLayout如何在 android.support.v4.widget.SwipeRefreshLayout 中设置空视图
【发布时间】:2015-09-07 19:37:41
【问题描述】:

我在这里看到了很多教程和其他东西来设置列表为空时的空视图。我有一个可以滑动刷新的列表。现在我想在列表视图为空时在文本视图中显示一条文本消息。我知道它可以像这样简单设置

myListview.setEmptyView(mEmptyViewContainer);

但当列表视图中的数据为空时,它不会设置文本视图。以下是阅读他通过将文本视图包装在单独的 swipeRefreshLayout 中解决的问题后对我的 xml 的修改。看看下面,这是我现在的 xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#dadada"

    >
        <RelativeLayout
    android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
       >

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

    <com.baoyz.swipemenulistview.SwipeMenuListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />




</android.support.v4.widget.SwipeRefreshLayout>
        </RelativeLayout>
    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipeRefreshLayout_emptyView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    <TextView
        android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="sdasdadadfdasf"
        android:layout_centerInParent="true"
        android:visibility="gone"
        android:gravity="center"
        /></ScrollView>
    </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>

所以现在我不明白为什么它没有显示我的空视图?可能是什么问题?或者请告诉我是否有其他方法可以做到这一点?代码 sn-p 将不胜感激。

【问题讨论】:

  • 一个相关的问题:我在SwipeRefreshLayout 中也有一个com.baoyz.swipemenulistview.SwipeMenuListView。但是左滑动手势与拉动刷新手势有某种冲突。我必须用更大的力量向左滑动并一直向左滑动以显示底层上下文按钮。这样做是不自然的。是否有某种敏感度设置或其他修复来避免这种冲突?你也经历过这样的事情吗?
  • 找到 this - 一个定制的 SwipeRefreshLayout 来解决我的问题。

标签: android listview swiperefreshlayout


【解决方案1】:

你可以这样做:

在你的 xml 中:

<RelativeLayout>
    <SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout">
    </SwipeRefreshLayout>
    <TextView
        android:id="@+id/layout_empty"/>
</RelativeLayout>

java代码:

swipeView = (SwipeRefreshLayout) getActivity().findViewById(R.id.swipe_refresh_layout);
layoutEmpty = getActivity().findViewById(R.id.layout_empty);

当列表视图为空时:

layoutEmpty.setVisibility(View.VISIBLE);

当列表视图不为空时:

layoutEmpty.setVisibility(View.INVISIBLE);

【讨论】:

  • @CoasMckey 你想在列表为空时显示消息吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-25
  • 1970-01-01
  • 2017-02-19
  • 1970-01-01
  • 2012-04-26
  • 1970-01-01
  • 2017-11-30
相关资源
最近更新 更多