簡體   English   中英

Android 應用程序中的平滑滾動

[英]Smooth scrolling in Android applications

我想將平滑滾動功能添加到我的應用程序中。 即我有一個巨大的文本,我想自動滾動它(就像在書籍閱讀器中一樣)。

誰能提供任何平滑滾動的例子?

只需將要滾動的視圖放入 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>

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM