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. 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>
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))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.