Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize UIScrollView of ios by android

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces android how to achieve ios UIScrollView related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this android how to achieve ios UIScrollView article will have a harvest, let's take a look.

First of all, the most important thing is to determine whether the current view is empty or not. it doesn't seem to make any difference whether you roll the empty view or not, except that the scrollview of android 5.0comes with that kind of Radian. There doesn't seem to be any soft use.

/ / scroll protected void onFinishInflate () {if (getChildCount () > 0) {childview = getChildAt (0);}} if the view is not empty.

I just learned about this property, which means that this method is called when all the layouts are rendered.

I enclose the methods commonly used by view, which you can study by yourselves. There are many methods I don't know.

Common ways to customize View:

OnFinishInflate () triggers when all child controls in View are mapped to xml

OnMeasure (int, int) determines the size of all child elements

OnLayout (boolean, int, int) triggers when View allocates the size and location of all child elements

OnSizeChanged (int, int) triggers when the size of the view changes

Details of onDraw (Canvas) view rendered content

OnKeyDown (int, KeyEvent) is triggered when a key is pressed.

OnKeyUp (int, KeyEvent) is triggered when the button is pressed and pops up.

OnTrackballEvent (MotionEvent) trackball event

OnTouchEvent (MotionEvent) touchscreen event

OnFocusChanged (boolean, int, Rect) triggers when View gains or loses focus

OnWindowFocusChanged (boolean) triggers when the view contained in the window gains or loses focus

OnAttachedToWindow () triggers when view is attached to a window

OnDetachedFromWindow () triggers when view leaves the attached window, indicating that the method is the opposite of onAttachedToWindow ().

OnWindowVisibilityChanged (int) triggers when the visible view contained in the window changes

These are the callback methods of some basic interfaces implemented by View. Generally speaking, when we need to deal with the display of the canvas, we use the most to rewrite onDraw (Canvas).

Then there is the ontouch event to determine the effect of displacement and springback:

If (childview! = null) {int action = event.getAction (); switch (action) {case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_UP: / / determine whether animation if (! normal.isEmpty ()) {animation (); isCount = false;} break is needed Case MotionEvent.ACTION_MOVE: final float DownY = startY; float moveY = event.getY (); int distance = (int) (DownY-moveY); if (! isCount) {distance = 0; / / return to 0 here. } startY = moveY; if (isNeedMove ()) {/ / Top if (normal.isEmpty ()) {normal.set (childview.getLeft (), childview.getTop (), childview.getRight (), childview.getBottom () } / / bottom childview.layout (childview.getLeft (), childview.getTop ()-distance / 2, childview.getRight (), childview.getBottom ()-distance / 2);} isCount = true; break;}

The next step is to determine whether the animation effects of scrolling and springback are needed.

Public void animation () {/ / enable mobile animation TranslateAnimation animation = new TranslateAnimation (0,0, childview.getTop (), normal.top); animation.setDuration; childview.startAnimation (animation); / / set back to the normal layout position childview.layout (normal.left, normal.top, normal.right, normal.bottom); normal.setEmpty () } public boolean isNeedMove () {int offset = childview.getHeight ()-getHeight (); int scrollY = getScrollY (); / / 0 is the top, followed by the bottom if (scrollY = = 0 | | scrollY = = offset) {return true;} return false;} this is the end of the article on "how android implements the UIScrollView of ios". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how android realizes the UIScrollView of ios". If you want to learn more knowledge, you are welcome to follow the industry information channel.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report