Android One pop-up menu animation (one)

Source: Internet
Author: User

First on:




Write the layout file first:

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:layout_width=" Fill_parent "Android: layout_height= "Fill_parent" android:background= "@android: Color/white" > <imageview android:id= " @+id/sat_main "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:src=" @drawable/sat_main "android:layout_alignparentbottom=" true "android:layout_alignparentleft=" true "an" droid:layout_marginleft= "5DP"/> <imageview android:id= "@+id/sat_item" Android:layout_wi Dth= "Wrap_content" android:layout_height= "wrap_content" android:visibility= "Gone" Android:layout_alignparentbotto M= "true" android:layout_alignparentleft= "true"/> <imageview android:id= "@+id/clone_item" Android : Layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:visibility= "Gone" android:layout_alignparentbottom= "true" Android:lay Out_alignparentleft= "true"/> </RelativeLayout>

These 3 ImageView are at the bottom of the screen, and the clone_item need to be fixed at the highest position of the ball bounce:

Initialize these 3 ImageView:

  Sat_main = (ImageView) Findviewbyid (R.id.sat_main); final ImageView Itemview = (ImageView) Findviewbyid (R.id.sat_item); Final ImageView Cloneview = (ImageView) Findviewbyid (R.id.clone_item); Cloneview.setimageresource ( R.drawable.searchable_web); Itemview.setimageresource (R.drawable.searchable_web); ItemView.setVisibility ( View.gone);


Initialize the location of the Cloneview:

This is where the cloneview is fixed to leftmargin x bottommargin y relativelayout.layoutparams layoutparams = ( Relativelayout.layoutparams) Cloneview.getlayoutparams (); layoutparams.bottommargin = Math.abs (y); Layoutparams.leftmargin = Math.Abs (x); Cloneview.setlayoutparams (Layoutparams);



When you click the button, the button itself rotates:

<?xml version= "1.0" encoding= "Utf-8"? ><rotatexmlns:android= "Http://schemas.android.com/apk/res/android"    android:interpolator= "@android: Anim/decelerate_interpolator"    android:fromdegrees= "0" android:todegrees = " -135"        android:pivotx= "50%" android:pivoty= "50%" android:duration= "+" android:fillafter= "true" Android: Fillenabled= "true"/>

The final position of the ball is obtained using the following method: X coordinate is distance*cos (angle), Y is distance*sin (angle)

Get distance cos (degree) public static int Gettranslatex (float degree, int distance) {return double.valueof (distance * Math.Cos (Math.toradians (degree))). Intvalue (); public static int Gettranslatey (float degree, int distance) {        return double.valueof ( -1 * distance * Math.sin (Math.tora Dians (degree)). Intvalue ();    


Then the ball bounces up the animation:

public static Animation Createitemoutanimation (context context, int index, long expandduration, int x, int y) {        Alphaanimation alphaanimation = new Alphaanimation (0f, 1f);        Long alphaduration = 60;        if (Expandduration <) {alphaduration = EXPANDDURATION/4;        } alphaanimation.setduration (Alphaduration);        Alphaanimation.setstartoffset (0);                 X and y are the coordinates of the ball bouncing to the highest point translateanimation translate = new Translateanimation (0, x, 0, y);        Translate.setstartoffset (0);         Translate.setduration (expandduration);        Overshootinterpolator: Indicates that a certain value is thrown forward before returning to its original position.                Translate.setinterpolator (context, r.anim.sat_item_overshoot_interpolator); Rotateanimation rotate = new Rotateanimation (0f, 360f, Animation.relative_to_self, 0.5f, an Imation.                Relative_to_self, 0.5f);        Accelerateinterpolator: Animation from start to finish, the rate of change is an accelerated process.   Decelerateinterpolator: Animation from start to finish, rate of change is a slowing down process     Rotate.setinterpolator (context, r.anim.sat_item_out_rotate_interpolator);        Long Duration = 100;        if (Expandduration <=) {duration = EXPANDDURATION/3;        } rotate.setduration (Expandduration-duration);                        Rotate.setstartoffset (duration);        Animationset animationset = new Animationset (false);        Animationset.setfillafter (FALSE);        Animationset.setfillbefore (TRUE);                        Animationset.setfillenabled (TRUE);        Animationset.addanimation (alphaanimation);        Animationset.addanimation (rotate);                Animationset.addanimation (translate);                Animationset.setstartoffset (30*index);    return animationset; }


When this animation bounces to the highest point, we have to make Itemview gone off, Cloneview visible


Location of code: http://download.csdn.net/detail/baidu_nod/7722621

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.