Android custom control 3-Youku menu animation, android3 --
The layout of Youku menu is implemented in the previous article, and the animation function is implemented in this article.
URL: http://www.cnblogs.com/wuyudong/p/5914901.html.
Create the animation tool class AnimationUtils. java. The Code is as follows:
Package com. wuyudong. youkumenu. utils; import android. view. animation. animation; import android. view. animation. rotateAnimation; import android. widget. relativeLayout; public class AnimationUtils {// public static void rotate (RelativeLayout layout, long delay) {RotateAnimation ra = new RotateAnimation (0f,-180f, // start, the end angle, which is counterclockwise Animation. RELATIVE_TO_SELF, 0.5f, // The relative x coordinate point (specify the rotation center x value) Animation. RELATIVE_TO_SELF, 1.0f); // The relative y coordinate point (specify the y value of the rotation center) ra. setDuration (1, 500); ra. setFillAfter (true); ra. setStartOffset (delay); layout. startAnimation (ra);} // public static void rotateInAnim (RelativeLayout layout) {RotateAnimation ra = new RotateAnimation (-180f, 0f, // start, end angle, clockwise Animation. RELATIVE_TO_SELF, 0.5f, // The relative x coordinate point (specify the rotation center x value) Animation. RELATIVE_TO_SELF, 1.0f); // The relative y coordinate point (specify the y value of the rotation center) ra. setDuration (1, 500); ra. setFillAfter (true); layout. startAnimation (ra );}}
Then write the logic part of the Code:
Package com. wuyudong. youkumenu; import com. wuyudong. youkumenu. utils. animationUtils; import android. OS. bundle; import android. app. activity; import android. view. menu; import android. view. view; import android. view. view. onClickListener; import android. widget. relativeLayout; public class MainActivity extends Activity implements OnClickListener {private RelativeLayout rl_level1; private RelativeLayout rl_level2; Private RelativeLayout rl_level3; private boolean islevel1Display = true; private boolean islevel2Display = true; private boolean islevel3Display = true; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); // initialize the control initViews ();} private void initViews () {// Add the Click Event findViewById (R. id. ib_home ). setOnClickListene R (this); findViewById (R. id. ib_menu ). setOnClickListener (this); rl_level1 = (RelativeLayout) findViewById (R. id. rl_level1); rl_level2 = (RelativeLayout) findViewById (R. id. rl_level2); rl_level3 = (RelativeLayout) findViewById (R. id. rl_level3);} @ Override public void onClick (View v) {switch (v. getId () {case R. id. ib_home: if (islevel2Display) {long delay = 200; // if the current three-level menu has been displayed, first transfer it out to if (islevel3Displ Ay) {AnimationUtils. rotateOutAnim (rl_level3, 0); islevel3Display = false; delay + = 200;} // if the current level-2 menu has been displayed, transfer it out to AnimationUtils. rotateOutAnim (rl_level2, delay);} else {// if the current level-2 menu is not displayed, transfer it to AnimationUtils. rotateInAnim (rl_level2);} islevel2Display =! Islevel2Display; break; case R. id. ib_menu: if (islevel3Display) {// if the current level-3 menu has been displayed, transfer it to AnimationUtils. rotateOutAnim (rl_level3, 0);} else {AnimationUtils. rotateInAnim (rl_level3);} islevel3Display =! Islevel3Display; break; default: break ;}}}
Basically implement menu Rotation