建布局文件:
<?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" android:background="#eeeeee" android:orientation="horizontal" android:gravity="center" >
<View android:id="@+id/vTop" android:layout_width="40dp" android:layout_height="40dp" android:background="@color/coral" />
<View android:id="@+id/vBottom" android:layout_width="40dp" android:layout_height="40dp" android:background="@color/deeppink" />
<View android:id="@+id/vLeft" android:layout_width="40dp" android:layout_height="40dp" android:background="@color/green" />
<View android:id="@+id/vRight" android:layout_width="40dp" android:layout_height="40dp" android:background="@color/red" />
<View android:id="@+id/vCenter" android:layout_width="40dp" android:layout_height="40dp" android:background="@color/blue" />
</RelativeLayout>
点击是开启动画:
private void startAnim(){
//透明度 旋转 平移
ObjectAnimator animator0=ObjectAnimator.ofFloat(vCenter,"alpha",1f,0.5f);
ObjectAnimator animator1=ObjectAnimator.ofFloat(vTop,"translationY",-300f);
ObjectAnimator animator5=ObjectAnimator.ofFloat(vTop,"rotation",0,360);
ObjectAnimator animator2=ObjectAnimator.ofFloat(vBottom,"translationY",300f);
ObjectAnimator animator6=ObjectAnimator.ofFloat(vBottom,"rotation",0,360);
ObjectAnimator animator3=ObjectAnimator.ofFloat(vLeft,"translationX",-300f);
ObjectAnimator animator7=ObjectAnimator.ofFloat(vLeft,"rotation",0,360);
ObjectAnimator animator4=ObjectAnimator.ofFloat(vRight,"translationX",300f);
ObjectAnimator animator8=ObjectAnimator.ofFloat(vRight,"rotation",0,360);
AnimatorSet set=new AnimatorSet();
set.setDuration(800);
set.playTogether(animator0, animator1, animator2, animator3, animator4,animator5,animator6,animator7,animator8);
set.start();
}
再次点击关闭:
private void closeAnim(){
ObjectAnimator animator0=ObjectAnimator.ofFloat(vCenter,"alpha",0.5f,1f);
ObjectAnimator animator1=ObjectAnimator.ofFloat(vTop,"translationY",0f);
ObjectAnimator animator5=ObjectAnimator.ofFloat(vTop,"rotation",0,360);
ObjectAnimator animator2=ObjectAnimator.ofFloat(vBottom,"translationY",0f);
ObjectAnimator animator6=ObjectAnimator.ofFloat(vBottom,"rotation",0,360);
ObjectAnimator animator3=ObjectAnimator.ofFloat(vLeft,"translationX",0f);
ObjectAnimator animator7=ObjectAnimator.ofFloat(vLeft,"rotation",0,360);
ObjectAnimator animator4=ObjectAnimator.ofFloat(vRight,"translationX",0f);
ObjectAnimator animator8=ObjectAnimator.ofFloat(vRight,"rotation",0,360);
AnimatorSet set=new AnimatorSet();
set.setDuration(800);
set.playTogether(animator0, animator1, animator2, animator3, animator4,animator5,animator6,animator7,animator8);
set.start();
}