今天就不做解说了,日后再来完善
private void showMenuBar() {
//设置动画时间
int duration = 5000;
//动画距离,屏幕宽度的60%
float distance = getScreenWidth()*0.6f;//432
//相邻ImageView运动角度式22.5度
float angle1 = (float)(22.5f*Math.PI/180);
float angle2 = (float)(45f*Math.PI/180);
float angle3 = (float)(67.5f*Math.PI/180);
//icon1
PropertyValuesHolder p1 = PropertyValuesHolder.ofFloat("TranslationX", 0f, -distance);
//icon2
PropertyValuesHolder p21 = PropertyValuesHolder.ofFloat("TranslationX", 0f, -(float)(distance*Math.cos(angle1)));
PropertyValuesHolder p22 = PropertyValuesHolder.ofFloat("TranslationY", 0f, -(float)(distance*Math.sin(angle1)));
//icon3
PropertyValuesHolder p31 = PropertyValuesHolder.ofFloat("TranslationX", 0f, -(float)(distance*Math.cos(angle2)));
PropertyValuesHolder p32 = PropertyValuesHolder.ofFloat("TranslationY", 0f, -(float)(distance*Math.sin(angle2)));
//icon4
PropertyValuesHolder p41 = PropertyValuesHolder.ofFloat("TranslationX", 0f, -(float)(distance*Math.cos(angle3)));
PropertyValuesHolder p42 = PropertyValuesHolder.ofFloat("TranslationY", 0f, -(float)(distance*Math.sin(angle3)));
//icon5
PropertyValuesHolder p5 = PropertyValuesHolder.ofFloat("TranslationY", 0f, -distance);
ObjectAnimator animator1 = ObjectAnimator.ofPropertyValuesHolder(mainBar1, p1).setDuration(duration);
ObjectAnimator animator2 = ObjectAnimator.ofPropertyValuesHolder(mainBar2, p21, p22).setDuration(duration);
ObjectAnimator animator3 = ObjectAnimator.ofPropertyValuesHolder(mainBar3, p31,p32).setDuration(duration);
ObjectAnimator animator4 = ObjectAnimator.ofPropertyValuesHolder(mainBar4, p41,p42).setDuration(duration);
ObjectAnimator animator5 = ObjectAnimator.ofPropertyValuesHolder(mainBar5, p5).setDuration(duration);
//添加自由落体效果插值器
animator1.setInterpolator(new BounceInterpolator());
animator2.setInterpolator(new BounceInterpolator());
animator3.setInterpolator(new BounceInterpolator());
animator4.setInterpolator(new BounceInterpolator());
animator5.setInterpolator(new BounceInterpolator());
//启动动画
animator1.start();
animator2.start();
animator3.start();
animator4.start();
animator5.start();
}
/**
* 竖屏时获取屏幕宽度,横屏时,获取高度
* @return
*/
public int getScreenWidth(){
DisplayMetrics outMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
int x = outMetrics.widthPixels;
int y = outMetrics.heightPixels;
return x>y?y:x;
}