早上无意看到了 优酷 这个应用,被这个应用的圆形转动盘菜单所吸引
于是闲来无事解压了 该客户端的APK,轻轻的取出需要的几张图片,对此我身怀愧疚,娃哈哈
搞了一下,主要是布局那块比较蛋疼点。
效果图:
MyAnimation.java
package com.ljp.youku;import android.view.ViewGroup;import android.view.animation.Animation;import android.view.animation.RotateAnimation;public class MyAnimation { // 图标的动画(入动画) public static void startAnimationsIn(ViewGroup viewgroup, int durationMillis) { viewgroup.setVisibility(0); for (int i = 0; i < viewgroup.getChildCount(); i++) { viewgroup.getChildAt(i).setVisibility(0); viewgroup.getChildAt(i).setClickable(true); viewgroup.getChildAt(i).setFocusable(true); } Animation animation; animation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1.0f); animation.setFillAfter(true); animation.setDuration(durationMillis); viewgroup.startAnimation(animation); } // 图标的动画(出动画) public static void startAnimationsOut(final ViewGroup viewgroup, int durationMillis, int startOffset) { Animation animation; animation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1.0f); animation.setFillAfter(true); animation.setDuration(durationMillis); animation.setStartOffset(startOffset); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation arg0) {} @Override public void onAnimationRepeat(Animation arg0) {} @Override public void onAnimationEnd(Animation arg0) { viewgroup.setVisibility(8); for (int i = 0; i < viewgroup.getChildCount(); i++) { viewgroup.getChildAt(i).setVisibility(8); viewgroup.getChildAt(i).setClickable(false); viewgroup.getChildAt(i).setFocusable(false); } } }); viewgroup.startAnimation(animation); }}
TestYoukuActivity.java
package com.ljp.youku;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.ImageButton;import android.widget.RelativeLayout;public class TestYoukuActivity extends Activity { /** Called when the activity is first created. */ private boolean areLevel2Showing = true, areLevel3Showing = true; private RelativeLayout relate_level2, relate_level3; private ImageButton home, menu; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); findViews(); setListener(); } private void findViews() { relate_level2 = (RelativeLayout) findViewById(R.id.relate_level2); relate_level3 = (RelativeLayout) findViewById(R.id.relate_level3); home = (ImageButton) findViewById(R.id.home); menu = (ImageButton) findViewById(R.id.menu); } private void setListener() { // 给大按钮设置点击事件 home.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!areLevel2Showing) { MyAnimation.startAnimationsIn(relate_level2, 500); } else { if (areLevel3Showing) { MyAnimation.startAnimationsOut(relate_level2, 500, 500); MyAnimation.startAnimationsOut(relate_level3, 500, 0); areLevel3Showing = !areLevel3Showing; } else { MyAnimation.startAnimationsOut(relate_level2, 500, 0); } } areLevel2Showing = !areLevel2Showing; } }); menu.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!areLevel3Showing) { MyAnimation.startAnimationsIn(relate_level3, 500); } else { MyAnimation.startAnimationsOut(relate_level3, 500, 0); } areLevel3Showing = !areLevel3Showing; } }); }}