【问题标题】:ListView scroll up bug using SmoothRefreshLayoutListView 使用 SmoothRefreshLayout 向上滚动错误
【发布时间】:2017-10-17 14:58:23
【问题描述】:

我在我的应用程序中实现了 SmoothRefreshLayout 库,目前它有一个简单的 ListView。 当我向下滚动 ListView 时会出现问题,当我尝试到达它的顶部时,它不会向上滚动,而是调用 Refresh 侦听器。所以运动卡住了。

这是activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<me.dkzwm.widget.srl.SmoothRefreshLayout

    android:id="@+id/smoothRefreshLayout"
    android:layout_width="match_parent"

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_centerInParent="true"
        android:indeterminateDrawable="@drawable/circular_spinner" >
    </ProgressBar>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/lv"

        />
</RelativeLayout>
</me.dkzwm.widget.srl.SmoothRefreshLayout>

这是 onCreate 中 RefreshListener 的一部分:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().setTitle("");
        setContentView(R.layout.activity_main);

        refreshLayout = (SmoothRefreshLayout)findViewById(R.id.smoothRefreshLayout);
        refreshLayout.setHeaderView(new MyCustomHeader(this));

        refreshLayout.setEnabled(true);
        refreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {
            @Override
            public void onRefreshBegin(boolean isRefresh) {

                if (isNetworkAvailable(MainActivity2.this)) {
                    isRef = true;
                    new upd().execute();
                } else {
                    Toast.makeText(MainActivity2.this, getResources().getString(R.string.err_conn), Toast.LENGTH_SHORT).show();
                }

            }

        });

【问题讨论】:

    标签: java android listview


    【解决方案1】:

    我知道自我回复没有意义,但它可能对其他人有所帮助。 无论如何,解决方案很简单,我刚刚实现了一个 onScrollListener 并检查第一项是否在顶部,如果不只是禁用 Refresher。

    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
                @Override
                public void onScrollStateChanged(AbsListView view, int scrollState) {
    
                }
    
                @Override
                public void onScroll(AbsListView listView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                    int rowpos = (listView == null || listView.getChildCount() == 0) ?
                            0 : listView.getChildAt(0).getTop();
                    refreshLayout.setEnabled((rowpos >= 0));
                }
            });
    

    致谢:Can't scroll in a ListView in a swipeRefreshLayout

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-04
      • 2015-06-06
      • 1970-01-01
      • 1970-01-01
      • 2014-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多