Full Screen animation for Android

Source: Internet
Author: User

By default, the animation is only valid for the current parent layout range. Sometimes, we need to do the floating effect in the full screen range. I think there are two actual practices:

1. Execute the animation with absolute coordinates

Set the animation type to absolute position for execution.

2. Simulate using the intermediate control. The intermediate control is the same as the view in setcontenview, and then calculates the Moving position for animation.

View. getparent () is used to obtain the viewgroup, and then viewgroup. addview (intermediate control) is used to animation the intermediate control.

Tip:

Getlocalvisiblerect: returns a filled rect object. Android gets the position of the view on the screen. It feels like the rect size of the view, left, Y value, // obtain the absolute coordinates getleft, gettop, getbottom, and getright in the window.
Getlocalvisiblerect: return a filled rect object. It feels like the rect size of this view, left and top get 0.
Getglobalvisiblerect: obtains a view area of the global coordinate system and returns a filled rect object. This rect is based on the total Screen
Getlocationonscreen: calculates the x and y values of the view in the global coordinate system. (Note that this value is counted from the top of the screen, that is, the height of the notification bar is included) // obtain the absolute coordinates on the current screen
Getlocationinwindow: calculates the X and Y coordinates of the view's widnow, and // obtains the absolute coordinates of the view within the window.
Getleft, gettop, getbottom, and getright are the coordinates of the parent group.

The Code is as follows:

Private void beginanimationandrefresh (final view fromview, final Boolean isback) {final viewgroup parent = (viewgroup) view. getparent (); // view is the final dailydateview newview = new dailydateview (activity. this); // you can use a custom view to create a new view as the intermediate view to execute the animated newview. setlayoutparams (fromview. getlayoutparams (); Final animationlistener listener = new animationlistener () {@ overridepublic void onanimationstart (animation) {fromview. setvisibility (view. invisible) ;}@ overridepublic void onanimationrepeat (animation) {}@ overridepublic void onanimationend (animation) {newview. setvisibility (view. gone); // do some handler operations after the animation ends. post (New runnable () {@ overridepublic void run () {parent. removeview (newview); If (isback) {dateweekview. setdailyviewshow (); setshowsiderview (false) ;}}) ;}}; handler. post (New runnable () {private animationset animation = new animationset (true); Private dailyviewanimation translateanim; private alphaanimation alphaanim; private rect fromrect; private rect torect; private rect stater; private int startx; private int starty; private int endx; private int Endy; private float startalpha; private float endalpha; @ overridepublic void run () {parent. addview (newview, fromview. getwidth (), fromview. getheight (); If (isback) {view toview = dateweekview. getdailyview (); fromrect = jingoaldisplayutil. getglobalrect (fromview); torect = jingoaldisplayutil. getglobalrect (toview); stater = jingoaldisplayutil. getstatebarrect (toview); startx = fromrect. left; starty = fromrect. top-stater. top; endx = torect. left; Endy = torect. top-stater. top; startalpha = 1f; endalpha = 0.5f;} else {view toitemview = gridview. getchildat (2); fromrect = jingoaldisplayutil. getglobalrect (fromview); torect = jingoaldisplayutil. getglobalrect (toitemview); stater = jingoaldisplayutil. getstatebarrect (toitemview); startx = fromrect. left; starty = fromrect. top; endx = torect. left; Endy = torect. top-stater. top; startalpha = 0.6f; endalpha = 1f;} translateanim = new dailyviewanimation (animation. absolute, animation. absolute, startx, endx, starty, Endy); alphaanim = new alphaanimation (startalpha, endalpha); animation. addanimation (translateanim); animation. addanimation (alphaanim); newview. setanimation (animation); animation. setduration (300); animation. setanimationlistener (listener); animation. start ();}});
Public class displayutil {static rect;/** after the value of outrect is attached to getwindowvisibledisplayframe (rect outrect) in the height view of the status bar, outrect. top () is the height of the status bar * getwindowvisibledisplayframe (rect outrect1) with the value outrect, outrect. height ()-view. getheight () is the title height. */Public static rect getstatebarrect (view v) {rect = new rect (); V. getwindowvisibledisplayframe (rect); Return rect;} public static rect getglobalrect (view v) {rect = new rect (); V. getglobalvisiblerect (rect); // retrieve the return rect coordinate of the view displayed in full screen ;}}
public class DailyViewAnimation extends TranslateAnimation {public DailyViewAnimation(int fromType, int toType, float fromXValue, float toXValue, float fromYValue, float toYValue) {super(fromType, fromXValue, toType, toXValue, fromType, fromYValue, toType, toYValue);}@Overrideprotected void applyTransformation(float interpolatedTime, Transformation t) {// int newHeight;// if (this.initiallyCollapsed) {// newHeight = (int) (this.deltaY * interpolatedTime);// } else {// newHeight = (int) (this.deltaY * (1 - interpolatedTime));// }// view.getLayoutParams().height = newHeight;// view.requestLayout();super.applyTransformation(interpolatedTime, t);}@Overridepublic void initialize(int width, int height, int parentWidth, int parentHeight) {super.initialize(width, height, parentWidth, parentHeight);}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.