android菜单动画,android一个弹出菜单的动画(一)

先上效果图:

116896_0.gif

先写Layout文件:

这3个ImageView都在屏幕的底部,clone_item需要固定在球弹起的最高位置:

初始化这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);

初始化cloneView的位置:

//这个是使cloneview固定在leftmargin x bottomMargin y的地方

RelativeLayout.LayoutParams layoutParams =(RelativeLayout.LayoutParams) cloneView.getLayoutParams();

layoutParams.bottomMargin = Math.abs(y);

layoutParams.leftMargin = Math.abs(x);

cloneView.setLayoutParams(layoutParams);

点击按钮时候,按钮本身会旋转:

用以下方法得到球的最终位置:x坐标是distance*cos(角度),y是distance*sin(角度)

//取得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.toRadians(degree))).intValue();

}

然后球弹起的动画:

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 < 60){

alphaDuration = expandDuration / 4;

}

alphaAnimation.setDuration(alphaDuration);

alphaAnimation.setStartOffset(0);

//x和y是球弹到最高点的坐标

TranslateAnimation translate = new TranslateAnimation(0, x, 0, y);

translate.setStartOffset(0);

translate.setDuration(expandDuration);

//OvershootInterpolator:表示向前甩一定值后再回到原来位置。

translate.setInterpolator(context, R.anim.sat_item_overshoot_interpolator);

RotateAnimation rotate = new RotateAnimation(0f, 360f,

Animation.RELATIVE_TO_SELF, 0.5f,

Animation.RELATIVE_TO_SELF, 0.5f);

//AccelerateInterpolator:动画从开始到结束,变化率是一个加速的过程。

//DecelerateInterpolator:动画从开始到结束,变化率是一个减速的过程

rotate.setInterpolator(context, R.anim.sat_item_out_rotate_interpolator);

long duration = 100;

if(expandDuration <= 150){

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;

}

这个动画弹到最高点后,我们得使itemview gone掉,cloneview visible

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值