安卓ScrollView的onScrollChanged方法

25

我在一个滚动视图的文本视图中有一个固定内容。当用户滚动到特定位置时,我想启动一个活动或触发一个 Toast

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent" android:layout_height="fill_parent"
 android:id="@+id/scroller">
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView android:layout_width="fill_parent" android:id="@+id/story"
   android:layout_height="wrap_content" android:text="@string/lorem"
   android:gravity="fill" />
 </LinearLayout>
</ScrollView>

我遇到的问题是实现受保护方法onScrollChanged以查找滚动视图的位置。

我发现了这个答案,除了像我发布的链接中所看到的那样声明接口、重写滚动视图等方式,是否有更简单的解决方案?


1
你可以使用以下代码来检测ScrollView的滚动是否到达底部: - Satria Akbar
11个回答

-1

从API 23 Android M开始,您可以使用OnScrollChangeListener。

 scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
        @Override
        public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            //work with parameters
        }
    });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接