Android的 - SwipeRefreshLayout空的TextView [英] Android - SwipeRefreshLayout with empty textview

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

问题描述

我实现了 SwipeRefreshLayout 进入我的应用程序,但它只能容纳一个直接子应该是列表视图。我试图找出如何一个空的TextView添加到下面的工作XML文件:

I've implemented SwipeRefreshLayout into my app but it can only hold one direct child which should be the listview. I'm trying to figure out how to add an empty textview to the following working XML file:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/listViewConversation"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:dividerHeight="1dp" />

</android.support.v4.widget.SwipeRefreshLayout>

包装在一个线性/相对布局使得它越野车,因为当你想滑备份列表视图列表视图会随时更新。我能想到的一个方法是通过编程这样做,但我想这是不是最好的选择。

Wrapping it in a Linear/Relative layout makes it buggy because the listview will always update when you want to slide back up the listview. One way I can think of is doing this programmatically but I guess that's not the best option.

您可以学习如何使用此教程来实现它:刷卡刷新指南

You can learn how to implement it using this tutorial: Swipe to refresh GUIDE

所以基本上这一切工作正常,但我想补充一个空的视图,显示一个消息,当列表视图是空的。

So basically it all works fine but I would like to add an empty view that shows a message when the listview is empty.

推荐答案

我不喜欢限制一个孩子。 此外,SwipeRefreshLayout的当前实现有一个硬codeD神奇处理了滚动,ListView控件和GridView只有触发,如果认为这是你自己的看法的直接孩子。

I didn't liked the limitation to a single child. Furthermore the current implementation of the SwipeRefreshLayout has an hardcoded "magic" handling for ScrollView, ListView and GridView that trigger only if the view it's the direct child of your own view.

这表示,好消息是,它是开源的,所以您可以复制code和适应您的需求,或者你可以做我所做的:

That said the good news it's that it is open source, so you can either copy the code and adapt to your needs or you can do what I did:

使用两个不同的SwipeRefreshLayout,一个是为ListView空视图和一个。

Use two DIFFERENT SwipeRefreshLayout, one for the Empty view and one for the ListView.

然后告诉你的ListView空列表视图是空观点的刷卡刷新布局。

Then tell your listview that the empty list view is the swipe refresh layout of the empty view.

现在空刷新布局将自动被当你有数据,将显示在列表为空的列表视图中隐藏起来。

Now the empty refresh layout will be automatically hidden by your list view when you have data and will be shown when the list is empty.

列表的刷卡刷新布局应该不会收到触摸事件造成的列表是隐藏的。

The swipe refresh layout of the list shouldn't receive touch events cause the list is hidden.

祝你好运。

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

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