android - 滑动刷新图标显示不正确

标签 android listview pull-to-refresh swiperefreshlayout

我正在使用 ListView并在使用 SwipeRefresh 向下滑动时刷新它,到这里为止一切正常。当我尝试设置 TextView 时出现问题在 mListview.setEmptyView() Refresh Icon滑动时不显示。

貌似在TextView下.但是,如果我不把它 TextView在同一个 XML 上它工作正常,但我需要在列表为空时显示一条消息。 是什么导致了这种行为?

这是我使用的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="@dimen/padding_light"
    android:paddingRight="@dimen/padding_light">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">

        <ListView
            android:id="@+id/mListView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

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

    <TextView
        android:id="@+id/swipeToRefreshTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="15dp"
        android:gravity="center_horizontal"
        android:text="@string/msg_swipe_to_refresh"
        android:visibility="gone" />

</RelativeLayout>

这是刷新监听器:

//Listeners
mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {

        //Here I do some job
        beaconScanSwipeRefresh.setRefreshing(false);
    }
});

这里是我设置 ListView 适配器的地方和 onEmptyView:

//UI
mListLv = (ListView) view.findViewById(R.id.mListView);
mSwipeRefresh=(SwipeRefreshLayout)view.findViewById(R.id.swipeRefreshLayout);
swipeToRefreshTv = (TextView)view.findViewById(R.id.swipeToRefreshTextView);

//Set Adapter
mListLv.setAdapter(mBaseAdapter);

//Set Message when list is empty
mListLv.setEmptyView(swipeToRefreshTv);

我试图移动我的 TextView里面<android.support.v4.widget.SwipeRefreshLayout标签或在它们之上。结果还是一样。

最佳答案

   <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="@dimen/padding_light"
    android:paddingRight="@dimen/padding_light">

<TextView
        android:id="@+id/swipeToRefreshTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"        
        android:gravity="center_horizontal"
        android:text="@string/msg_swipe_to_refresh"
        android:visibility="gone" />

    <android.support.v4.widget.SwipeRefreshLayout
        //below = swipeToRefreshTextView
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">

        <ListView
            android:id="@+id/mListView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

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



</RelativeLayout>

请以这种方式更新您的布局并检查。

关于android - 滑动刷新图标显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28106720/

相关文章:

ios - UITableview 刷新单元格在节标题下滚动

ios - 在 tableView 上拉动刷新

java - SQLHelper 的游标返回带指数的数字

android - 加载下一个新项目android时如何更新 ListView ?

java - Libgdx for android 在主屏幕前显示黑色

android - 在 2.3 上不显示 AdMobs,但在带有 Google Play 服务的 Android 4+ 上显示

android - Flutter 是否有上下文操作栏,用于从 ListView 中选择多个项目

listview - Windows 8 ListView 不会以 100% 高度呈现

java - Android 抽屉式导航失败

swift - 检测何时快速调用 pullToRefresh