Android Sliding effect Advanced (v) 3D rotation

Source: Internet
Author: User
Tags final

The previous introduction of the use of Android's own control, sliding page making effect, now we use code to achieve some sliding page animation effect.

Animation animations are implemented in two ways: Frame animation (Frame-by-frame animation) and motion tweens (tweened animation)

This example implements the 3D paging effect by inheriting animation custom Rotate3d. The effect chart is as follows:

1, Rotate3d (Animation)

First, customize the animation 3D animation class Rotate3d

public class Rotate3d extends Animation {private float fromdegree;     Rotation starting angle private float todegree;     Rotary Termination angle private float Mcenterx;     Rotary Center x private float Mcentery;     

    Rotary Center y private Camera Mcamera; Public Rotate3d (float fromdegree, float todegree, float centerx, float centery) {this.fromdegree = Fromdegre     
        E     
        This.todegree = Todegree;     
        This.mcenterx = CenterX;     
         
    This.mcentery = CenterY;     
        @Override public void Initialize (int width, int height, int parentwidth, int parentheight) {     
        Super.initialize (width, height, parentwidth, parentheight);     
    Mcamera = new Camera (); @Override protected void applytransformation (float interpolatedtime, transformation t) {fin     
        Al float fromdegree = fromdegree; Float degrees = fromdegree + (todegree-fromdegree) * interpolatedtiMe     
        Rotation angle (angle) Final float CenterX = Mcenterx;     
        Final float centery = mcentery;     

        Final Matrix matrix = T.getmatrix ();     
            if (degrees <= -76.0f) {degrees = -90.0f;     
            Mcamera.save ();       Mcamera.rotatey (degrees);     
            Rotating Mcamera.getmatrix (matrix);     
        Mcamera.restore ();     
            else if (degrees >= 76.0f) {degrees = 90.0f;     
            Mcamera.save ();     
            Mcamera.rotatey (degrees);     
            Mcamera.getmatrix (matrix);     
        Mcamera.restore ();     
            else {mcamera.save ();       Mcamera.translate (0, 0, CenterX);     
            Displacement x mcamera.rotatey (degrees);     
            Mcamera.translate (0, 0,-centerx);     
            Mcamera.getmatrix (matrix);     
        Mcamera.restore (); } matrix.pretranslate (-centerx,-ceNtery);     
    Matrix.posttranslate (CenterX, centery); }     
}

Related Article

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.