Example of a toggle animation between activity in Android

Source: Internet
Author: User
Tags stub


You can add some cool animations when the activity is switched,
The implementation code is as follows:

Mainactivity:

Package Com.example.administrator.swichlayoutdemo;

Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.view.Window;
Import Android.widget.Button;

Import com.tandong.swichlayout.BaseEffects;
Import Com.tandong.swichlayout.SwitchLayout;

public class Mainactivity extends activity {
Private Button Btn_ok, btn_1, Btn_2, Btn_3, Btn_4, Btn_5, Btn_6, Btn_7,
Btn_8, Btn_9, Btn_10, Btn_11, Btn_12, btn_13, btn_14;

@Override
protected void OnCreate (Bundle savedinstancestate) {
Requestwindowfeature (Window.feature_no_title);
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Initview ();

Set up activity-specific animations that can be expanded into layout animations
Switchlayout.getslidefrombottom (this, false,
Baseeffects.getquicktosloweffect ());
Three parameters are (Activity/view, whether to close the activity, special effects (nullable))
Initlistener ();
}

    private void Initlistener () {
        btn_ Ok.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View arg0) {
TODO auto-generated Method Stub
Intent in = new Intent (mainactivity.this, Secondactivity.class);
In.putextra ("key", 0);
MainActivity.this.startActivity (in);
}
});

Btn_1.setonclicklistener (New Onclicklistener () {

            @Override
             public void OnClick (View arg0) {
                //TODO auto-generated method stub
                 Intent in = new Intent (Mainactivity.this, Secondactivity.class);
                In.putextra ("key ", 1);
                MainActivity.this.startActivity (in);
           }
       });
        Btn_2.setonclicklistener (New Onclicklistener () {

            @Override
             public void OnClick (View arg0) {
                //TODO auto-generated method stub
                 Intent in = new Intent (Mainactivity.this, Secondactivity.class);
                In.putextra ("key ", 2);
                MainActivity.this.startActivity (in);
           }
       });
        Btn_3.setonclicklistener (New Onclicklistener () {

            @Override
             public void OnClick (View arg0) {
                //TODO auto-generated method stub
                 Intent in = new Intent (Mainactivity.this, Secondactivity.class);
                In.putextra ("key ", 3);
                MainActivity.this.startActivity (in);
           }
       });
        Btn_4.setonclicklistener (New Onclicklistener () {

            @Override
             public void OnClick (View arg0) {
                //TODO auto-generated method stub
                 Intent in = new Intent (Mainactivity.this, Secondactivity.class);
                In.putextra ("key ", 4);
                MainActivity.this.startActivity (in);
           }
       });
        Btn_5.setonclicklistener (New Onclicklistener () {

            @Override
             public void OnClick (View arg0) {
                //TODO auto-generated method stub
                 Intent in = new Intent (Mainactivity.this, Secondactivity.class);
                In.putextra ("key ", 5);
                MainActivity.this.startActivity (in);
           }
       });
        Btn_6.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View arg0) {
TODO auto-generated Method Stub
Intent in = new Intent (mainactivity.this, Secondactivity.class);
In.putextra ("Key", 6);
MainActivity.this.startActivity (in);
}
});

Btn_7.setonclicklistener (New Onclicklistener () {

            @Override
             public void OnClick (View arg0) {
                //TODO auto-generated method stub
                 Intent in = new Intent (Mainactivity.this, Secondactivity.class);
                In.putextra ("key ", 7);
                MainActivity.this.startActivity (in);
           }
       });
        Btn_8.setonclicklistener (New Onclicklistener () {

            @Override
             public void OnClick (View arg0) {
                //TODO auto-generated method stub
                 Intent in = new Intent (Mainactivity.this, Secondactivity.class);
                In.putextra ("key ", 8);
                MainActivity.this.startActivity (in);
           }
       });
        Btn_9.setonclicklistener (New Onclicklistener () {

            @Override
             public void OnClick (View arg0) {
                //TODO auto-generated method stub
                 Intent in = new Intent (Mainactivity.this, Secondactivity.class);
                In.putextra ("key ", 9);
                MainActivity.this.startActivity (in);
           }
       });
        Btn_10.setonclicklistener (New Onclicklistener () {

            @Override
             public void OnClick (View arg0) {
                //TODO auto-generated method stub
                 Intent in = new Intent (Mainactivity.this, Secondactivity.class);
                In.putextra ("key ", 10);
                MainActivity.this.startActivity (in);
           }
       });
        Btn_11.setonclicklistener (New Onclicklistener () {

            @Override
             public void OnClick (View arg0) {
                //TODO auto-generated method stub
                 Intent in = new Intent (Mainactivity.this, Secondactivity.class);
                In.putextra ("key ", 11);
                MainActivity.this.startActivity (in);
           }
       });
        Btn_12.setonclicklistener (New Onclicklistener () {

            @Override
             public void OnClick (View arg0) {
                //TODO auto-generated method stub
                 Intent in = new Intent (Mainactivity.this, Secondactivity.class);
                In.putextra ("key ", 12);
                MainActivity.this.startActivity (in);
           }
       });
        Btn_13.setonclicklistener (New Onclicklistener () {

            @Override
             public void OnClick (View arg0) {
                //TODO auto-generated method stub
                 Intent in = new Intent (Mainactivity.this, Secondactivity.class);
                In.putextra ("key ", 13);
                MainActivity.this.startActivity (in);
           }
       });
        Btn_14.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View arg0) {
TODO auto-generated Method Stub
Intent in = new Intent (mainactivity.this, Secondactivity.class);
In.putextra ("key", 14);
MainActivity.this.startActivity (in);
}
});
}

private void Initview () {


BTN_OK = (Button) This.findviewbyid (R.ID.BTN_OK);


btn_1 = (Button) This.findviewbyid (r.id.btn_1);


Btn_2 = (Button) This.findviewbyid (r.id.btn_2);


Btn_3 = (Button) This.findviewbyid (r.id.btn_3);


Btn_4 = (Button) This.findviewbyid (r.id.btn_4);


Btn_5 = (Button) This.findviewbyid (r.id.btn_5);


Btn_6 = (Button) This.findviewbyid (r.id.btn_6);


Btn_7 = (Button) This.findviewbyid (r.id.btn_7);


Btn_8 = (Button) This.findviewbyid (r.id.btn_8);


Btn_9 = (Button) This.findviewbyid (r.id.btn_9);


Btn_10 = (Button) This.findviewbyid (R.ID.BTN_10);


Btn_11 = (Button) This.findviewbyid (r.id.btn_11);


Btn_12 = (Button) This.findviewbyid (R.id.btn_12);


Btn_13 = (Button) This.findviewbyid (r.id.btn_13);


Btn_14 = (Button) This.findviewbyid (r.id.btn_14);

}
}
Secondactivity:

Package Com.example.administrator.swichlayoutdemo;

Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import android.view.KeyEvent;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.view.Window;
Import Android.widget.ImageView;

Import com.tandong.swichlayout.BaseEffects;
Import Com.tandong.swichlayout.SwichLayoutInterFace;
Import Com.tandong.swichlayout.SwitchLayout;

public class Secondactivity extends activity implements Swichlayoutinterface {
Private Intent Intent;
Private ImageView Iv_back;
private int key = 0;

    @Override
    protected void onCreate (Bundle savedinstancestate) {
         requestwindowfeature (Window.feature_no_title);
        super.oncreate (savedinstancestate);
        Setcontentview (R.layout.activity_second);
        initintent ();
       //Set activity effects animation into the activity, the same can be extended to layout animation
         setenterswichlayout ();
   }

private void Initintent () {
Intent = getintent ();
Key = Intent.getextras (). GetInt ("key");
Iv_back = (ImageView) This.findviewbyid (r.id.iv_back);
Iv_back.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View arg0) {
Setexitswichlayout ();
}
});
}

public boolean onKeyDown (int keycode, keyevent event) {//To exit the activity effects animation when the return key is pressed

if (keycode = = Keyevent.keycode_back && event.getrepeatcount () = = 0) {
Setexitswichlayout ();
return true;
}
Return Super.onkeydown (KeyCode, event);
}

@Override


public void Setenterswichlayout () {


Switch (key) {


Case 0:


Switchlayout.get3drotatefromleft (this, false, NULL);


Three parameters are (Activity/view, whether to close the activity, special effects (nullable))


Break


Case 1:


Switchlayout.getslidefrombottom (this, false,


Baseeffects.getmoresloweffect ());


Break


Case 2:


Switchlayout.getslidefromtop (this, false,


Baseeffects.getrescrolleffect ());


Break


Case 3:


Switchlayout.getslidefromleft (this, false,


Baseeffects.getlinearintereffect ());


Break


Case 4:


Switchlayout.getslidefromright (this, false, NULL);


Break


Case 5:


Switchlayout.getfadingin (this);


Break


Case 6:


Switchlayout.scalebig (this, false, NULL);


Break


Case 7:


Switchlayout.flipupdown (this, false,


Baseeffects.getquicktosloweffect ());


Break


Case 8:


Switchlayout.scalebiglefttop (this, false, NULL);


Break


Case 9:


Switchlayout.getshakemode (this, false, NULL);


Break


Case 10:


Switchlayout.rotateleftcenterin (this, false, NULL);


Break


Case 11:


Switchlayout.rotatelefttopin (this, false, NULL);


Break


Case 12:


Switchlayout.rotatecenterin (this, false, NULL);


Break


Case 13:


Switchlayout.scaletobighorizontalin (this, false, NULL);


Break


Case 14:


Switchlayout.scaletobigverticalin (this, false, NULL);


Break


Default


Break


}

}

@Override


public void Setexitswichlayout () {


Switch (key) {


Case 0:


Switchlayout.get3drotatefromright (this, true, NULL);


Break


Case 1:


Switchlayout.getslidetobottom (this, true,


Baseeffects.getmoresloweffect ());


Break


Case 2:


Switchlayout.getslidetotop (this, true,


Baseeffects.getrescrolleffect ());


Break


Case 3:


Switchlayout.getslidetoleft (this, true,


Baseeffects.getlinearintereffect ());


Break


Case 4:


Switchlayout.getslidetoright (this, true, NULL);


Break


Case 5:


Switchlayout.getfadingout (this, true);


Break


Case 6:


Switchlayout.scalesmall (this, true, NULL);


Break


Case 7:


Switchlayout.flipupdown (this, true,


Baseeffects.getquicktosloweffect ());


Break


Case 8:


Switchlayout.scalesmalllefttop (this, true, NULL);


Break


Case 9:


Switchlayout.getshakemode (this, true, NULL);


Break


Case 10:


Switchlayout.rotateleftcenterout (this, true, NULL);


Break


Case 11:


Switchlayout.rotatelefttopout (this, true, NULL);


Break


Case 12:


Switchlayout.rotatecenterout (this, true, NULL);


Break


Case 13:


Switchlayout.scaletobighorizontalout (this, true, NULL);


Break


Case 14:


Switchlayout.scaletobigverticalout (this, true, NULL);


Break


Default


Break


}

}

}

Where the powerful animation effect depends on the animation library Switchlayout1.0.jar package

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.