Advanced six Android UI interface (interface 3D rotation)

Source: Internet
Author: User

Inf. Perhaps you pay the not necessarily to be rewarded, but do not pay must not be rewarded.


The content of this lecture: interface 3D rotation


Example one:



Here is the Res/layout/activity_main.xml layout file:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/    Android "android:id=" @+id/layout_main "android:layout_width=" fill_parent "android:layout_height=" Wrap_content " android:orientation= "vertical" ><textview android:id= "@+id/title" android:layout_width= "Wrap_content" Androi d:layout_height= "wrap_content" android:layout_gravity= "center" android:gravity= "Center" android:textcolor= "# ff0000 "android:text=" @string/txt_main "/> <linearlayout android:layout_margintop=" 50dip "Android:layout_ Width= "Wrap_content" android:layout_height= "wrap_content" android:gravity= "center" android:layout_gravity= "center "><buttonandroid:id=" @+id/main_last "android:layout_width=" wrap_content "android:layout_height=" Wrap_ Content "android:text=" on page "/><button android:id=" @+id/main_next "android:layout_marginleft=" 50dip "Android: Layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "next page"/></linearlaYout></linearlayout> 

here is the Res/layout/next.xml layout file:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/    Android "android:id=" @+id/layout_next "android:layout_width=" fill_parent "android:layout_height=" Wrap_content " android:orientation= "vertical" ><textview android:id= "@+id/title" android:layout_width= "Wrap_content" Androi d:layout_height= "wrap_content" android:layout_gravity= "center" android:gravity= "Center" android:textcolor= "# ff0000 "android:text=" @string/txt_next "/> <linearlayout android:layout_margintop=" 5dip "android:layout_width = "Wrap_content" android:layout_height= "wrap_content" android:gravity= "center" android:layout_gravity= "Center" > <buttonandroid:id= "@+id/next_last" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:text= "Previous"/><button android:id= "@+id/next_next" android:layout_marginleft= "50dip" Android:layout_ Width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "next page"/></linearlayOut></linearlayout> 

here is the Res/values/string.xml file:

<?xml version= "1.0" encoding= "Utf-8"?><resources>    <string name= "App_name" >rotate3d</ string>    <string name= "Hello_world" >hello world!</string>    <string name= "Action_settings" >Settings</string>    <string name= "Txt_main" > the first page \ n \ nyou Cherish life </string>    <string name= " Txt_next "> second page \ n away from it</string></resources>

here is the Rotate3d.java file:

public class Rotate3d extends Animation {private float fromdegree;//rotation start angle private float todegree;//rotation end angle Private float m centerx;//Rotary Center xprivate float mcentery;//Rotary Center yprivate Camera mcamera;public Rotate3d (float fromdegree, float todegree, F Loat CenterX, float centery) {this.fromdegree = Fromdegree;this.todegree = Todegree;this.mcenterx = CenterX; This.mcentery = CenterY;} @Overridepublic void Initialize (int width, int height, int parentwidth, int parentheight) {super.initialize (width, height , Parentwidth, parentheight); Mcamera = new Camera ();} @Overrideprotected void Applytransformation (float interpolatedtime, transformation t) {final float Fromdegree = Fromdegree;float degrees = Fromdegree + (todegree-fromdegree) * interpolatedtime;//rotation angle (angle) Final float CenterX = mCe nterx;final float centery = mcentery;final Matrix matrix = T.getmatrix (); if (degrees <= -76.0f) {degrees = -90.0f;mcame Ra.save (); Mcamera.rotatey (degrees);//Spin 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 xmcamera.rotatey (degrees); mcamera.translate (0, 0,- CenterX); Mcamera.getmatrix (matrix); Mcamera.restore ();} Matrix.pretranslate (-centerx,-centery); Matrix.posttranslate (CenterX, CenterY);}}

here is the Mainactivity.java main interface file:

public class Mainactivity extends Activity {private ViewGroup layoutmain;private viewgroup layoutnext;private Button btn_ Mainlast;private button btn_mainnext;private button btn_nextlast;private button btn_nextnext;private Rotate3D Lquest1animation;private rotate3d lquest2animation;private Rotate3d rquest1animation;private Rotate3D rquest2animation;private int Mcenterx = 160;//320x480 width half private int mcentery = 240;//320x480 high half @overridepublic void        OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Initanimation (); Initmain ();} private void Initmain () {Layoutmain = (linearlayout) Findviewbyid (r.id.layout_main); btn_mainlast = (Button) Findviewbyid (r.id.main_last); btn_mainnext = (Button) Findviewbyid (r.id.main_next); Btn_mainlast.setonclicklistener (listener); Btn_mainnext.setonclicklistener (listener);} private void Initnext () {Setcontentview (r.layout.next); layoutnext = (linearlayout) Findviewbyid (R. id.layout_next); btn_nextlast = (Button) Findviewbyid (r.id.next_last); btn_nextnext = (Button) Findviewbyid (R.id.next _next); Btn_nextlast.setonclicklistener (listener); Btn_nextnext.setonclicklistener (listener);} Private View.onclicklistener listener = new View.onclicklistener () {@Overridepublic void OnClick (View v) {switch (V.getid ()) {Case r.id.main_last://previous page layoutmain.startanimation (lquest1animation);//Current page rotate Left (0,-90) Initnext (); Layoutnext.startanimation (lquest2animation);//Next page Rotate Left (0) break;case r.id.main_next:// Next page layoutmain.startanimation (rquest1animation);//Current page rotate Right (0,90) Initnext (); Layoutnext.startanimation ( rquest2animation);//The next page rotates to the right ( -90, 0) break;case r.id.next_last:layoutnext.startanimation (lquest1animation); Initmain (); layoutmain.startanimation (lquest2animation); Break;case r.id.next_next:layoutnext.startanimation ( rquest1animation); Initmain (); layoutmain.startanimation (rquest2animation); break;}}; public void Initanimation () {//Get rotation center displaymetrics DM = new Displaymetrics ();d m =Getresources (). Getdisplaymetrics () Mcenterx = Dm.widthpixels/2;mcentery = dm.heightpixels/2;//defines the direction of rotation int duration = 10 00;lquest1animation = new Rotate3d (0, -90, Mcenterx, mcentery);//The direction of rotation of the next page (from 0 degrees to 90, The reference system is a horizontal direction of 0 degrees) Lquest1animation.setfillafter (true); lquest1animation.setduration (duration); lquest2animation = new Rotate3d (0, Mcenterx, mcentery);//The rotation direction of the next page (from 90 degrees to 0, the reference system is horizontal 0 degrees) (starting with the first question) Lquest2animation.setfillafter (true); Lquest2animation.setduration (duration); rquest1animation = new Rotate3d (0, N, Mcenterx, mcentery);//The direction of rotation of the previous page (from 0 degrees to 90 , the reference system is a horizontal direction of 0 degrees) Rquest1animation.setfillafter (true); rquest1animation.setduration (duration); rquest2animation = new Rotate3d ( -90, 0, Mcenterx, mcentery);//The rotation direction of the previous page (from 90 degrees to 0, the reference system is horizontally 0 degrees) Rquest2animation.setfillafter (true); Rquest2animation.setduration (duration);}}

Take your time and enjoy it


Advanced six Android UI interface (interface 3D rotation)

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.