首先,属性动画是不用依赖的
定义xml文件中的图片
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:id="@+id/linearlayout"
android:gravity="center"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@mipmap/ic_launcher_round"/>
在activity中设置 代码如下:
public class MainActivity extends AppCompatActivity {
private ImageView image;
private LinearLayout linearlayout;
private int width;
private int height;
private int time;
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (time==0){
startActivity(new Intent(MainActivity.this,FragMentActivity.class));
finish();
}
time--;
handler.sendEmptyMessageDelayed(0,1000);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = findViewById(R.id.image);
linearlayout = findViewById(R.id.linearlayout);
time=4;
handler.sendEmptyMessageDelayed(0,1000);
//平移
ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(image, "translationY",image.getTranslationY(), 400);
//旋转
ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(image, "rotationY", 0, 360);
//透明
ObjectAnimator objectAnimator3 = ObjectAnimator.ofFloat(image,"alpha",0,1,0,1);
//缩放
ObjectAnimator objectAnimator4 = ObjectAnimator.ofFloat(image, "scaleX", 0, 1);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setDuration(4000);
animatorSet.play(objectAnimator1).with(objectAnimator2).with(objectAnimator3).with(objectAnimator4);
animatorSet.start();
}
}