带有空 TextView 的 Android SwipeRefreshLayout 无法正常工作 [英] Android SwipeRefreshLayout with empty TextView not working properly

查看:25
本文介绍了带有空 TextView 的 Android SwipeRefreshLayout 无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是,允许用户滑动和刷新列表,数据是否存在都没有关系.但是当列表视图中有数据时,只有列表视图应该可见,而当数据不存在时,空文本视图应该是可见的.在这两种情况下,用户都必须能够通过滑动来刷新列表.

What i want to do is , allow user to swipe and refresh the list, it does not matter if the data is there or not. But when data is there in the listview only the listview should be visible, and when data is not there , Empty textview should be visible. In both the cases user must be able to refresh list by swipe.

我尝试了一些解决方案在本次讨论中 但它们听起来都不起作用,采用两个 SwipeToRefresh 的想法有效此处 没问题,但即使在从服务器获取数据时它也显示空容器.

I tried some solution given here in this discussion but none of them sounds working, the idea of taking two SwipeToRefresh works fine as given Here, but it shows empty container even while fetching data from server.

我用我自己的逻辑将 Listview 和 Textview 包装在一个相对/FrameLayout 中进行了尝试,但 SwipeToRefresh 仅根据其行为接受一个视图

I tried it with my own logic wrapping Listview and Textview inside a Relative/FrameLayout but SwipeToRefresh accepts one view only as per its behavior

这是我尝试过的 xml 片段

Here is an xml snippet i have tried

 <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>

请帮忙

推荐答案

我用FrameLayout解决了同样的问题,看下面的代码:

I solved same problem by using FrameLayout, look at below code:

<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>

您也可以使用 RelativeLayout,但关键是将 ListView 放在 SwipeRefreshLayout 内,将 TextView 放在外面.

You could use RelativeLayout as well, but the key is placing your ListView inside the SwipeRefreshLayout, and the TextView outside.

这篇关于带有空 TextView 的 Android SwipeRefreshLayout 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆