Android 应用程序中的平滑滚动

发布于 2024-10-04 00:41:42 字数 84 浏览 0 评论 0原文

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

谁能提供平滑滚动的任何示例?

I would like to add the smooth scrolling functionality into my application.
i.e. I have a huge text and I want to scroll it automatically (like in book readers).

Could anyone offer any examples of smooth scrolling?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

走野 2024-10-11 00:41:42

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

<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>

Just put the view(s) you want to scroll inside a ScrollView. So to put some text in a scrolling area, put the text in a TextView, and then the TextView inside a ScrollView, like this:

<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>
浅浅 2024-10-11 00:41:42

使用反射更新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))

Use reflection to update the ScrollView's Scroller:

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

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

Use smoothScrollTo method (may have to setSmoothScrolligEnabled(true))

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文