//布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activity.MainActivity">
<TextView
android:layout_marginTop="300dp"
android:textSize="50dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电商" />
<ImageView
android:id="@+id/dh"
android:layout_marginTop="400dp"
android:layout_gravity="center"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/tu"/>
<Button
android:id="@+id/kai"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开启旅程"/>
</LinearLayout>
//MainActivity
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ImageView dh;
private Button kai;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dh = findViewById(R.id.dh);
kai = findViewById(R.id.kai);
kai.setOnClickListener(this);
}
@Override
public void onClick(View v) {
ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(dh, "alpha", 0.8f,0 );
objectAnimator1.setInterpolator(new AccelerateInterpolator());
// objectAnimator1.start();
ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(dh,"rotation",0,180);
// objectAnimator2.start();
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(objectAnimator2).with(objectAnimator1);
animatorSet.setDuration(2000);
animatorSet.start();
animatorSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
Intent intent = new Intent(MainActivity.this,TwoActivity.class);
startActivity(intent);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
}