我在这里看到了许多教程和其他内容,用于在列表为空时设置空视图。我有一个可以滑动刷新的列表。现在,我想在列表视图为空时在文本视图中显示一条文本消息。我逐渐知道,像这样设置是很简单的
myListview.setEmptyView(mEmptyViewContainer);但是当列表视图中的数据为空时,它不会设置文本视图。下面是在阅读了一个问题后对我的xml的修改,他通过将文本视图包装在单独的swipeRefreshLayout中解决了这个问题。如下所示,这就是我的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>所以现在我不明白为什么它不显示我的空视图?会有什么问题呢?或者请告诉我有没有其他的方法?代码片段将不胜感激。
发布于 2015-09-08 11:21:26
你可以这样做:
在您的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);https://stackoverflow.com/questions/32445074
复制相似问题