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)
而已.
我也遇到了这个问题,并通过使用下面的布局在活动中没有任何额外代码的情况下解决了这个问题。
如果您使用 aListActivity或ListFragment它会为您处理显示/隐藏空视图,并且使用此布局结构刷新空列表也可以工作。
不需要 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 按预期工作。
| 归档时间: |
|
| 查看次数: |
16136 次 |
| 最近记录: |