Summary of Android implementation methods
Summary of Android implementation methods
This paper provides seven methods for Android sliding. Each implementation method is introduced in detail. You can refer to it as needed,
1.1 using layout method
We know that when the view is drawing, the onlayout method will be called to set the display position. Similarly, you can control the coordinates of the view through the four properties of left, top, right and button of the view. Every time we are on the touch event, we have to get the coordinates of the touch point.
1.2 use offsetleftandright(), offsettopandbottom()
As long as you know the offset, you can use this method for pet painting. It is equivalent to a package of left-right offset and up-down offset.
1.3 using layoutparms to move views
Note that you must use the layout pamrs of the parent layout type, otherwise an error will occur here; Of course, there is a simpler method. If you use viewgroup.marginlayoutparams, you don't need to consider your type of parent control.
1.4 using scrollyto and scrollby
In view, the system provides two methods, scrollyto and scrollyby, to change the position of the view. These two methods are very easy to understand. Scrollyto is to move to a specified location, and scrollyby is to move an offset of the view. In fact, it also calls the scrollyto method. They can only change the content layout of the view, not the position of the view itself. They do not realize the real sliding. What they change is the position of the content. If it is used in the ViewGroup, all child views will be moved, and if it is used in the view, the content of the view will be moved. What's more, their movement is completed in an instant, which has been completed when the event is triggered.
1.5 using scroller
Through the screener, we can move the view smoothly,
1.6 attribute animation
1.7 viewdraghelper
Through viewraghelper, we can basically realize various animation operations. However, his use method is complex:
Thank you for reading, hope to help you, thank you for your support to this site!