Bha*_*hta 8 android android-listview swiperefreshlayout
我想要做的是,允许用户刷卡并刷新列表,无论数据是否存在都无关紧要.但是当列表视图中存在数据时,列表视图应该是可见的,而当数据不存在时,应该看到空文本视图.在这两种情况下,用户必须能够通过滑动刷新列表.
我在这个讨论中尝试了一些解决方案 ,但没有一个听起来有效,采取两个SwipeToRefresh的想法在这里给出的工作正常,但它甚至在从服务器获取数据时显示空容器.
我用自己的逻辑包装Listview和Textview在Relative/FrameLayout中尝试了它,但SwipeToRefresh仅根据其行为接受一个视图
这是我尝试过的xml片段
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.945" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/event_list_eventlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/event_background"
android:dividerHeight="1dp" >
</ListView>
<TextView
android:id="@+id/event_txt_nothing_found"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/darker_gray"
android:visibility="gone" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
请帮忙
Phu*_*ran 13
我通过使用FrameLayout解决了同样的问题,请看下面的代码:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/layout_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="@+id/lv_products"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null" />
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:id="@+id/tv_no_product"
style="@android:style/TextAppearance.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:gravity="center"
android:text="@string/msg_no_listing"
android:textColor="@color/primary_green"
android:visibility="gone" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
您也可以使用RelativeLayout,但关键是将ListView放在SwipeRefreshLayout和TextView外部.
avb*_*avb 12
我也有这个问题,并通过使用下面的布局解决了它在活动中没有任何额外的代码.
如果您正在使用a ListActivity或ListFragment它处理显示/隐藏空视图,并刷新使用空列表以及此布局结构.
不需要黑客,一切都在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)
希望它可以帮助任何人解决这个问题.