android 高仿【优酷】圆盘旋转菜单 的实现

MyAnimation.java
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);
}

}

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
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;
}
});
}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值