简体   繁体   English

Android 应用程序中的平滑滚动

[英]Smooth scrolling in Android applications

I would like to add the smooth scrolling functionality into my application.我想将平滑滚动功能添加到我的应用程序中。 ie I have a huge text and I want to scroll it automatically (like in book readers).即我有一个巨大的文本,我想自动滚动它(就像在书籍阅读器中一样)。

Could anyone offer any examples of smooth scrolling?谁能提供任何平滑滚动的例子?

Just put the view(s) you want to scroll inside a ScrollView.只需将要滚动的视图放入 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:因此,要将一些文本放入滚动区域,请将文本放入 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>

Use reflection to update the ScrollView's Scroller:使用反射更新 ScrollView 的 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))使用 smoothScrollTo 方法(可能需要 setSmoothScrolligEnabled(true))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM