由于某些原因,即使ListView不为空,空视图(在本例中为TextView )也会始终出现。我认为ListView会自动检测何时显示空视图。
<RelativeLayout android:id="@+id/LinearLayoutAR"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView android:id="@+id/ARListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"></ListView>
<ProgressBar android:id="@+id/arProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"></ProgressBar>
<!-- Here is the view to show if the list is emtpy -->
<TextView android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No Results" />
</RelativeLayout>
如何正确地连接空视图?
发布于 2010-09-23 00:48:15
应该是这样的:
<TextView android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No Results" />
请注意id属性。
发布于 2012-04-14 07:24:23
正如appsthatmatter所说,在布局中类似于:
<ListView android:id="@+id/listView" ... />
<TextView android:id="@+id/emptyElement" ... />
在链接的活动中:
this.listView = (ListView) findViewById(R.id.listView);
this.listView.setEmptyView(findViewById(R.id.emptyElement));
也适用于GridView..。
发布于 2014-01-02 15:32:20
我强烈建议您像这样使用ViewStubs
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ViewStub
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout="@layout/empty" />
</FrameLayout>
查看来自Cyril Mottier的完整示例
https://stackoverflow.com/questions/3771568
复制相似问题