Activity.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<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"/>
</LinearLayout>
Activity.java代码:
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AnimationSet;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
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, "translationX", 0,0,400,0 );
//旋转
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();
}
}