android - 拉动刷新:ListView 在动画时中断

标签 android pull-to-refresh

我正在使用此 PullToRefresh 代码:

<强> https://github.com/erikwt/PullToRefresh-ListView

XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/bg_listview_grey" >

    <eu.erikw.PullToRefreshListView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="6dp"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="6dp"
        android:divider="@color/bg_listview_grey"
        android:dividerHeight="6dp"
        android:drawSelectorOnTop="true"
        android:scrollbars="none" />

</RelativeLayout>

与ListView相关的 Activity 代码:

listView = (PullToRefreshListView) view
        .findViewById(R.id.feedListView);
footerView = inflater.inflate(R.layout.footer, listView, false);
feedListView.addFooterView(footerView);
listAdapter = new DefaultFeedAdapter((Activity) getSherlockActivity(),
        list_items, listView);
listView.setAdapter(listAdapter);

feedListView.setOnScrollListener(new OnScrollListener() {
    public void onScrollStateChanged(AbsListView view, int scrollState) {
    }

    public void onScroll(AbsListView view, int firstVisibleItem,
            int visibleItemCount, int totalItemCount) {

        // what is the bottom item that is visible
        int lastInScreen = firstVisibleItem + visibleItemCount;
        // is the bottom item visible & not loading more already ? Load
        // more !
        if ((lastInScreen == totalItemCount) && totalItemCount >= 3
                && !LoadingNextData && !noMoreItems) {
            lastId = listAdapter.values.get(totalItemCount - 3).id;
            LoadingNextData = true;
            new GetNewItems().execute("" + lastId);
        }
    }
});

listView.setOnRefreshListener(new OnRefreshListener() {
    @Override
    public void onRefresh() {
        new RefreshList().execute("");
    }
});

private class RefreshFeed extends AsyncTask<String, Void, String> {
    //adds items at the top of the list if there are any.
    //But even without any new items ie.. without touching
    //the listView, it breaks.
}

问题是:

enter image description here

While loading, it breaks 40% of the bottom listView and when it gets loaded it breaks some 20% of the listViewand finally shows the whole listView.

我错过了什么吗?请帮忙。

谢谢。

最佳答案

这不是解决您问题的方法,但可以使用:

<强> https://github.com/chrisbanes/Android-PullToRefresh

虽然上面写着

PLEASE NOTE, THIS PROJECT IS NO LONGER BEING MAINTAINED

它运行完美,界面流畅。

就像 @Udi Oshi 建议的那样,您也可以使用 Gmail Like 拉动来刷新:

<强> https://github.com/chrisbanes/ActionBar-PullToRefresh

关于android - 拉动刷新:ListView 在动画时中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16996285/

相关文章:

c# - Unity 中基于 Google Games Services 回合制多人游戏的自定义 UI

ios - 无法通过下拉刷新 tableview Controller 中的刷新我的 JSON 数据

android - 当第一个 Observable 为空时 RxJava concat

android - 如何在 Android 上创建此自定义底部导航

android getContentResolver().notifyChange() 不重启我的装载机

java - ArrayList 的后备数组的长度与 ArrayList 的 .size() 不同

flutter - 使用 RefreshIndicator 时,无法将参数类型 'Future<List<User>>' 分配给 onRefresh 中的参数类型 'Future<void> Function()'

ios - UITableView 单元格在滚动时损坏

android-studio - Pulltorefresh 添加到 gradle