In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use Scroller in Android". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn how to use Scroller in Android.
The Scroller class in Android is a Helper class that implements smooth scrolling of View. Usually used when customizing View, define a private member mScroller = new Scroller (context) in View. Setting the position of mScroller scrolling does not cause View scrolling. It usually records / calculates the position of View scrolling with mScroller, and then overrides the computeScroll () of View to complete the actual scrolling.
The related API is introduced as follows
MScroller.getCurrX () / / get the current horizontal scrolling position of the mScroller mScroller.getCurrY () / / get the current vertical scrolling position of the mScroller mScroller.getFinalX () / / get the horizontal position of the final stop of the mScroller mScroller.getFinalY () / / get the vertical position of the final stop of the mScroller mScroller.setFinalX (int newX) / / set the horizontal position of the final stay of the mScroller, no animation effect Jump directly to the target position mScroller.setFinalY (int newY) / / set the vertical position where the mScroller finally stays, without animation effect, jump directly to the target position / / scroll, startX, startY to start scrolling position Dx,dy is the offset of scrolling, and duration is the time to complete scrolling mScroller.startScroll (int startX, int startY, int dx, int dy) / / use the default completion time 250ms mScroller.startScroll (int startX, int startY, int dx, int dy, int duration) mScroller.computeScrollOffset () / / the return value indicates that scrolling has not been completed, and false indicates that scrolling has been completed. This is an important method, usually placed in View.computeScroll (), to determine whether scrolling ends or not.
For example, customize a CustomView and use Scroller to scroll:
Import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.widget.LinearLayout; import android.widget.Scroller; public class CustomView extends LinearLayout {private static final String TAG = "Scroller"; private Scroller mScroller; public CustomView (Context context, AttributeSet attrs) {super (context, attrs); mScroller = new Scroller (context) } / / call this method to scroll to the target location public void smoothScrollTo (int fx, int fy) {int dx = fx-mScroller.getFinalX (); int dy = fy-mScroller.getFinalY (); smoothScrollBy (dx, dy) } / / call this method to set the relative offset of scrolling public void smoothScrollBy (int dx, int dy) {/ / set the scrolling offset of mScroller mScroller.startScroll (mScroller.getFinalX (), mScroller.getFinalY (), dx, dy); invalidate () / / invalidate () must be called here to ensure that computeScroll () will be called, otherwise the interface may not necessarily be refreshed No scrolling effect} @ Override public void computeScroll () {/ / first determine whether mScroller scrolling is completed if (mScroller.computeScrollOffset ()) {/ / call View's scrollTo () here to complete the actual scrolling scrollTo (mScroller.getCurrX (), mScroller.getCurrY ()) / / this method must be called, otherwise you may not be able to see the scrolling effect postInvalidate ();} super.computeScroll ();}} so far, I believe you have a better understanding of "how to use Scroller in Android". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.