0

我试图知道用户何时滚动到屏幕末尾。

我的布局是 ScrollView。

我创建了新的服装 ScrollView 对象来覆盖 onScrollChanged 使用这里的代码:

检测 ScrollView 的结束

我知道用户何时滚动到屏幕末尾的代码是:

我在我的滚动视图下方的布局中创建视图,称为checkEndOfList.

在我的代码中,我尝试检查列表的末尾是否显示。

我的 XML:

 <com.example.workoutlog.WallScrollView
        android:id="@+id/wallList"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stackFromBottom="true"
        android:transcriptMode="alwaysScroll" >

        <LinearLayout
            android:id="@+id/workoutsWall"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
        </LinearLayout>
    </com.example.workoutlog.WallScrollView>

    <LinearLayout
        android:id="@+id/checkEndOfList"
        android:layout_width="fill_parent"
        android:layout_height="0.1sp"
        android:layout_below="@+id/wallList"
        android:orientation="horizontal"
        android:background="@color/transparent" >
    </LinearLayout>

这是我用于检查用户是否滚动到页面末尾的 java 代码:

@Override
        public void onScrollChanged(WallScrollView scrollView, int x,
                int y, int oldx, int oldy) {
            // TODO Auto-generated method stub          
            if(y - oldy == 0 && checkEndOfList.isShown() && y != 0 && oldy != 0)
            {
//MY CODE
}

我尝试的代码对我不起作用。即使我没有滚动屏幕,我也会收到屏幕结束的呼叫。

感谢您的帮助。

4

1 回答 1

0

你可以这样使用:

    private int visibleThreshold = 5;
    private int currentPage = 0;
    private int previousTotal = 0;
    private boolean loading = true;

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem,
            int visibleItemCount, int totalItemCount) {
        if (loading) {
            if (totalItemCount > previousTotal) {
                loading = false;
                previousTotal = totalItemCount;
                currentPage++;
            }
        }
        if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
            // I load the next page of gigs using a background task,
            // but you can call any function here.
            new LoadGigsTask().execute(currentPage + 1);
            loading = true;
        }
    }
于 2013-08-21T14:01:46.200 回答