Android应用程序中的平滑滚动

问题描述 投票:0回答:2

我想在我的应用程序中添加平滑滚动功能。即我有一个很大的文本,我想自动滚动它(就像在阅读器中一样)。

有人可以提供平滑滚动的任何示例吗?

android scroll smoothing
2个回答
4
投票

只需将要滚动的视图放在ScrollView中。因此,要在滚动区域中放置一些文本,请将文本放置在TextView中,然后在ScrollView中放置TextView,如下所示:

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
        <TextView
            android:id="@+id/my_view_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        />
</ScrollView>

0
投票

使用反射来更新ScrollView的Scroller:

Field mScroller;
mScroller = ScrollView.class.getDeclaredField("mScroller");
mScroller.setAccessible(true);

CustomScroller scroller = new CustomScroller(getContext(), new AccelerateInterpolator());
mScroller.set(this, scroller);

使用smoothScrollTo方法(可能必须设置setSmoothScrolligEnabled(true))

© www.soinside.com 2019 - 2024. All rights reserved.