Mimic the cat's Eye movie app with an animated effect

Source: Internet
Author: User

Look at the real cat's eye.

Next look at your own written rough figure (the lack of place is here is 2 switch options, if you need 3 switches, you need to customize the control, follow-up in the update ... )


Source Address http://download.csdn.net/download/u013210620/8795799

First look at the main page XML layout file--so easy

Activity_main.xml

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Tools:context = "Com.example.mytogglebutton.MainActivity" > <relativelayout android:layout_width= "150DP" android:l ayout_height= "50DP" android:layout_centerinparent= "true" android:background= "#CD5555" > <textvi            EW android:id= "@+id/tv_left" android:layout_width= "50DP" android:layout_height= "40DP" Android:layout_alignparentleft= "true" android:layout_centervertical= "true" Android:layout_ma rginleft= "15DP" android:gravity= "center" android:text= "shopping"/> <textview Android Oid:id= "@+id/tv_up" android:layout_width= "50DP" android:layout_height= "40DP" Android:layo Ut_alignparentleft= "true" Android:Layout_centervertical= "true" android:layout_marginleft= "15DP" android:background= "#ffffff"            android:gravity= "center" android:text= "shopping"/> <textview android:id= "@+id/tv_right" Android:layout_width= "50DP" android:layout_height= "40DP" android:layout_alignparentright= "t Rue "Android:layout_centervertical=" true "android:layout_marginright=" 15DP "Android:gravi ty= "Center" android:text= "gourmet"/> </RelativeLayout></RelativeLayout>

mainactivity--See main layout code--so easy

Package Com.example.mytogglebutton;import Android.app.activity;import Android.os.bundle;import Android.view.View; Import Android.view.view.onclicklistener;import Android.view.animation.animation;import Android.view.animation.translateanimation;import Android.widget.textview;import Android.widget.Toast;public Class Mainactivity extends Activity implements Onclicklistener {private TextView tv_left;private TextView tv_right;private TextView tv_up;//Indicates whether to switch from shopping to gourmet private Boolean Tv_up_left_tran = false;//indicates whether to switch from gourmet to shopping private Boolean Tv_up_right_tran = false; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Initview (); Tv_right.setonclicklistener (this); Tv_left.setonclicklistener (this);} private void Initview () {tv_left = (TextView) Findviewbyid (r.id.tv_left); tv_right = (TextView) Findviewbyid (r.id.tv_ right); tv_up = (TextView) Findviewbyid (R.ID.TV_UP);} @Overridepublic void OnClick (View v) {switch (V.getid ()) {CASe r.id.tv_left://says to switch from gourmet to shopping if (!tv_up_right_tran) {translateanimation animation = new Translateanimation ( Animation.relative_to_self, 1.4f,animation.relative_to_self, 0f,animation.relative_to_self, 0.0f, Animation.relative_to_self, 0.0f); animation.setduration (+); Tv_up.settext ("shopping"); Animation.setfillafter (true); Tv_up.startanimation (animation);} After switching, modify the state--you can switch from the left to the right, but not from the right to the left Tv_up_right_tran = True;tv_up_left_tran = false; Toast.maketext (This, "" +tv_up.gettext (), 1). Show (); Break;case r.id.tv_right://means to switch from shopping to gourmet if (!tv_up_left_tran) { Translateanimation animation1 = new Translateanimation (animation.relative_to_self, 0.0f,animation.relative_to_self, 1.4f,animation.relative_to_self, 0.0f,animation.relative_to_self, 0.0f); animation1.setduration (+); tv_ Up.settext ("Gourmet"); Tv_up.startanimation (Animation1); Animation1.setfillafter (true);} After switching, modify the state--you can switch from the right to the left, but not from the left to the right Tv_up_left_tran = True;tv_up_right_tran = false; Toast.maketext (This, "" +tv_up.gettext (), 1). Show (); break;default:break;}}}



Mimic the cat's Eye movie app with an animated effect

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.