Let's take a look at the effect
Analysis of the implementation principle:
Here the main knowledge point is the use of animation, the principle of the page is very simple, in an Activity layout two Fragment, not Fragment also line, but in the same XML, the amount of code will be relatively large; when initializing, let the second fagment move to the bottom and hide it. Just start the application interface, click Start, the corresponding animation, the first Fragment x and y are both reduced, and the beginning of the X rotation 25 degrees, and so on for a certain time, so that the x rotation angle of restoration, this process is the Fragment of the backward movement of the animation process, At the same time there is a black background setting its transparency, from full to 0.5f, the second fragment animation is very simple, simple downward and upward movement.
Here to put a part of the code out, interested to understand the source can be directly downloaded to study.
Paste the code process:
Move animation backwards
Mhoverview. Setclickable(true); / * Set Background transparency animation * /Objectanimator animator = Objectanimator. Offloat(Mhoverview,"Alpha",0,0.5F; / * Play small x animation * /Objectanimator Scalexanim = Objectanimator. Offloat(Moriginalview,"ScaleX",1.0F. 8F; / * Play small y animation * /Objectanimator Scaleyanim = Objectanimator. Offloat(Moriginalview,"ScaleY",1.0F. 8F;Animatorset animatorset = new Animatorset ();Animatorset. Playtogether(Animator, Scalexanim, Scaleyanim);Animatorset. Setduration( -);Animatorset. Start(); / * Let x rotate 20-degree animation first * /Objectanimator TRANSX = Objectanimator. Offloat(Moriginalview,"RotationX",20.0F;Transx. Setduration( Max);Transx. Start(); / * Wait for a certain time to reset the x rotation angle * /Objectanimator Resumex = Objectanimator. Offloat(Moriginalview,"RotationX",0.0F;Resumex. Setduration( $);Resumex. Setstartdelay( Max);Resumex. Start();
Know the backward animation, the reverse animation is very good understanding
Mhoverview. Setclickable(false);Objectanimator animator = Objectanimator. Offloat(Mhoverview,"Alpha",0.5F0);Objectanimator Scalexanim = Objectanimator. Offloat(Moriginalview,"ScaleX",. 8F1.0F;Objectanimator Scaleyanim = Objectanimator. Offloat(Moriginalview,"ScaleY",. 8F1.0F;Animatorset animatorset = new Animatorset ();Animatorset. Playtogether(Animator, Scalexanim, Scaleyanim);Animatorset. Setduration( -);Animatorset. Start();Objectanimator TRANSX = Objectanimator. Offloat(Moriginalview,"RotationX",20.0F;Transx. Setduration( Max);Transx. Start();Objectanimator Resumex = Objectanimator. Offloat(Moriginalview,"RotationX",0.0F;Resumex. Setduration( $);Resumex. Setstartdelay( Max);Resumex. Start();
The following is an animation of the second Fragment moving up and down
/** * Created by Moon.zhong on 2015/4/12. * * Public class Animationcompat implements Runnable { PrivateScroller Mscroller;PrivateView Manimationview;Private intMviewheight;Private Final intDURATION = -; Public Animationcompat(Context context, view view) {Mscroller =NewScroller (Context,NewLinearinterpolator ()); Manimationview = view; Mviewheight = Manimationview.getmeasuredheight ();if(Mviewheight = =0) {Manimationview.getviewtreeobserver (). Addonpredrawlistener (NewViewtreeobserver.onpredrawlistener () {@Override Public Boolean Onpredraw() {manimationview.getviewtreeobserver (). Removeonpredrawlistener ( This); Mviewheight = Manimationview.getmeasuredheight ();return false; } }); } } Public void starthideanimation(BooleanScrollup) {intDY = (int) Viewcompat.gettranslationy (Manimationview) + mviewheight;if(!scrollup) {dy = (int) Viewcompat.gettranslationy (Manimationview)-mviewheight; }intDuration = (int) Math.Abs (DURATION * Viewcompat.gettranslationy (Manimationview) *1.0F/mviewheight); Duration = Duration = =0? Duration:duration; Mscroller.startscroll (0, (int) Viewcompat.gettranslationy (Manimationview),0,-dy, duration); Viewcompat.postonanimation (Manimationview, This); } Public void startshawanimation() {intDY = (int) Viewcompat.gettranslationy (Manimationview);intDuration = (int) Math.Abs (DURATION); Mscroller.startscroll (0Dy0,-dy, duration); Viewcompat.postonanimation (Manimationview, This); } Public void abortanimation() {mscroller.abortanimation (); }@Override Public void Run() {if(Mscroller.computescrolloffset ()) {Viewcompat.postonanimation (Manimationview, This); Viewcompat.settranslationy (Manimationview, Mscroller.getcurry ()); } }}
Mainactivity's XML page is posted because it involves the layout of the fragment
<relativelayout xmlns:android="Http://schemas.android.com/apk/res/android" android:layout_width="Match_parent"android:layout_height="Match_parent" android:background="@android: Color/black"android:id="@+id/id_anim_content" > <fragment class =< Span class= "Hljs-value" > "com.test.gyzhong.funanimator.OriginalFragment" Android:layout_width = "match_parent" android : layout_height = "match_parent" android:id
= "@+id/id_original_fragment" /> <view android:layout_ Width = "match_parent" android:layout_height< /span>= "match_parent" android:id = "@+id/id_hover_view" android:background =" @android: Color/black " android:alpha =" 0 "/> <relativelayout android: ID = "@+id/id_bottom_view" android:layout_ Width = "match_parent" android:layout_height< /span>= "400DP" android:background = "@android: Color/white" android:layout_alignparentbottom< /span>= "true" android:layout_marginright =< Span class= "Hljs-value" > "50DP" android:layout_marginleft =" 50DP "; <fragmentclass="Com.test.gyzhong.funanimator.AnimFragment"android:layout _width="Match_parent"android:layout_height="Match_parent"android:id= "@+id/id_fragment_instruct" /> </relativelayout></relativelayout>
If you put all two Fragment layouts in this layout file, the code will be very ugly, all in one file!
Summarize:
No summary, is to be cooked using attribute animation!
Demo Source
A more interesting Android animation effect