【问题标题】:Check scrollview at bottom-android在bottom-android检查滚动视图
【发布时间】:2015-04-23 18:00:42
【问题描述】:

请,如果用户滚动底部的滚动视图,我想为用户显示弹出窗口,我如何检查底部的滚动视图? 有没有办法检查?

【问题讨论】:

标签: android


【解决方案1】:

在你的情况下:ScrollView,请检查http://developer.android.com/reference/android/widget/ScrollView.html#onOverScrolled%28int,%20int,%20boolean,%20boolean%29 - Klotor

实现一个 OnScrollListener,设置你​​的 ListView 的 onScrollListener,然后你应该能够正确处理事情了。

例如:

private int preLast;

// 初始化的东西。 yourListView.setOnScrollListener(this);

// ... ... ...

@Override
public void onScroll(AbsListView lw, final int firstVisibleItem,
                 final int visibleItemCount, final int totalItemCount) {
    switch(lw.getId()) {
        case android.R.id.list:     

            // Make your calculation stuff here. You have all your
            // needed info from the parameters of this function.

            // Sample calculation to determine if the last 
            // item is fully visible.
           final int lastItem = firstVisibleItem + visibleItemCount;
           if(lastItem == totalItemCount) {
              if (preLast != lastItem){ //to avoid multiple calls for last item
                Log.d("Last", "Last");
                preLast = lastItem;
                //show your popup code
              }
           }
    }
}

【讨论】:

【解决方案2】:

试试这样的:

@Override
 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    View view = (View) getChildAt(getChildCount()-1);
    int diff = (view.getBottom()-(getHeight()+getScrollY()+view.getTop()));// Calculate the scrolldiff
    if( diff == 0 ){  // if diff is zero, then the bottom has been reached
        Log.d(ScrollTest.LOG_TAG, "MyScrollView: Bottom has been reached" );
    }
    super.onScrollChanged(l, t, oldl, oldt);
}

感谢Harry Joylink

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-30
    • 1970-01-01
    相关资源
    最近更新 更多