Custom Controls-rotation animation, custom controls Rotation
RotateAnimation (float fromDegrees, float toDegrees, int limit txtype, float limit txvalue, int limit tytype, float limit tyvalue)
Parameter description:
Float fromDegrees: the starting angle of rotation.
Float toDegrees: the end angle of the rotation.
Int limit txtype: The scaling mode of the X axis. values include ABSOLUTE, RELATIVE_TO_SELF, and RELATIVE_TO_PARENT.
Float limit txvalue: The scaling value of X coordinates.
Int equaltytype: The scaling mode of the Y axis. values include ABSOLUTE, RELATIVE_TO_SELF, and RELATIVE_TO_PARENT.
Float tytyvalue: The scaling value of Y coordinates.
// Animation. setRepeatCount (int repeatCount); // you can specify the number of repetitions.
// Animation. setFillAfter (boolean); // whether the animation is in the running state after execution
// Animation. setStartOffset (long startOffset); // the waiting time before execution
Package com.org. demo. youku; import com.org. wangfeng. r; import android. app. activity; import android. OS. bundle; import android. view. keyEvent; import android. view. view; import android. view. view. onClickListener; import android. widget. imageView; import android. widget. relativeLayout; public class MainActivity extends Activity implements OnClickListener {private ImageView iv_home, iv_menu; private RelativeLayout Level1, level2, level3; private boolean isShowLevel2 = true; // whether to display Level 2 menu private boolean isShowLevel3 = true; // whether to display Level 3 menu private boolean isShowMenu = true; // whether to display the entire menu, including Level 1, level 2, and level 3 menu @ Override protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stub super. onCreate (savedInstanceState); setContentView (R. layout. mainyouku); iv_home = (ImageView) findViewById (R. id. iv_home ); Iv_menu = (ImageView) findViewById (R. id. iv_menu); level1 = (RelativeLayout) findViewById (R. id. level1); level2 = (RelativeLayout) findViewById (R. id. level2); level3 = (RelativeLayout) findViewById (R. id. level3); iv_home.setOnClickListener (this); iv_menu.setOnClickListener (this) ;}@ Override public void onClick (View arg0) {// TODO Auto-generated method stub switch (arg0.getId ()) {case R. id. iv_home: If (AnimUtil. animCount! = 0) {// indicates that an animation is executing return;} if (isShowLevel2) {// int startOffset = 0 needs to be hidden; if (isShowLevel3) {AnimUtil. closeMenu (level3, startOffset); startOffset + = 200; isShowLevel3 = false;} AnimUtil. closeMenu (level2, startOffset);} else {// you need to display AnimUtil. showMenu (level2, 0);} isShowLevel2 =! IsShowLevel2; break; case R. id. iv_menu: if (AnimUtil. animCount! = 0) {// indicates that an animation is executing return;} if (isShowLevel3) {// hide Level 3 menu AnimUtil. closeMenu (level3, 0);} else {// displays Level 3 menu AnimUtil. showMenu (level3, 0);} isShowLevel3 =! IsShowLevel3; break; default: break; }}@ Override public boolean onKeyDown (int keyCode, KeyEvent event) {if (keyCode = KeyEvent. KEYCODE_MENU) {if (isShowMenu) {// you need to disable all menu int startOffset = 0; if (isShowLevel3) {AnimUtil. closeMenu (level3, startOffset); isShowLevel3 = false; startOffset + = 200;} if (isShowLevel2) {AnimUtil. closeMenu (level2, startOffset); isShowLevel2 = false; startOffset + = 200;} AnimUtil. closeMenu (level1, startOffset);} else {// All menus need to be displayed AnimUtil. showMenu (level1, 0); AnimUtil. showMenu (level2, 200); isShowLevel2 = true; AnimUtil. showMenu (level3, 400); isShowLevel3 = true;} isShowMenu =! IsShowMenu; return true;} return super. onKeyDown (keyCode, event );}}
Package com.org. demo. youku; import android. view. animation. animation; import android. view. animation. rotateAnimation; import android. view. animation. animation. animationListener; import android. widget. relativeLayout; public class AnimUtil {public static int animCount = 0; // record the number of currently executed animations public static void closeMenu (RelativeLayout rl, int startOffset) {for (int I = 0; I <rl. getChildCount (); I ++) {rl. getChildAt (I ). setEnabled (false);} // optional txvalue: 0-1 RotateAnimation animation = new RotateAnimation (0,-180, RotateAnimation. RELATIVE_TO_SELF, 0.5f, RotateAnimation. RELATIVE_TO_SELF, 1); animation. setDuration (500); animation. setFillAfter (true); // The animation is still in the animation state after the animation ends. setStartOffset (startOffset); animation. setAnimationListener (new MyAnimationListener (); rl. startAnimation (animation);} public static void showMenu (RelativeLayout rl, int startOffset) {for (int I = 0; I <rl. getChildCount (); I ++) {rl. getChildAt (I ). setEnabled (true);} RotateAnimation animation = new RotateAnimation (-180, 0, RotateAnimation. RELATIVE_TO_SELF, 0.5f, RotateAnimation. RELATIVE_TO_SELF, 1); animation. setDuration (500); animation. setFillAfter (true); // The animation is still in the animation state after the animation ends. setStartOffset (startOffset); animation. setAnimationListener (new MyAnimationListener (); rl. startAnimation (animation);} static class implements AnimationListener {@ Override public void onAnimationStart (Animation animation) {animCount ++;} @ Override public void Merge (Animation animation) {animCount -- ;}@ Override public void onAnimationRepeat (Animation animation ){}}}
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- --> <RelativeLayout android:layout_width="100dp" android:id="@+id/level1" android:layout_height="50dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="@drawable/level1" > <ImageView android:id="@+id/iv_home" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@drawable/icon_home" android:contentDescription="@null" /> </RelativeLayout> <RelativeLayout android:id="@+id/level2" android:layout_width="180dp" android:layout_height="90dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="@drawable/level2" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:background="@drawable/icon_search" android:contentDescription="@null" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="10dp" android:layout_marginRight="10dp" android:background="@drawable/icon_myyouku" android:contentDescription="@null" /> <ImageView android:id="@+id/iv_menu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:background="@drawable/icon_menu" android:contentDescription="@null" /> </RelativeLayout> <RelativeLayout android:id="@+id/level3" android:layout_width="280dp" android:layout_height="142dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="@drawable/level3" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="15dp" android:layout_marginLeft="12dp" android:background="@drawable/channel1" android:contentDescription="@null" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="15dp" android:layout_marginRight="12dp" android:background="@drawable/channel5" android:contentDescription="@null" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="55dp" android:layout_marginLeft="32dp" android:background="@drawable/channel2" android:contentDescription="@null" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="55dp" android:layout_marginRight="32dp" android:background="@drawable/channel6" android:contentDescription="@null" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="85dp" android:layout_marginLeft="62dp" android:background="@drawable/channel3" android:contentDescription="@null" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="85dp" android:layout_marginRight="62dp" android:background="@drawable/channel7" android:contentDescription="@null" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:background="@drawable/channel4" android:contentDescription="@null" /> </RelativeLayout></RelativeLayout>