属性动画的小圆球运动完成进行跳转

xiaoxiao2025-11-02  4

 

 

 

public class TimeActivity extends AppCompatActivity { private ImageView img_ball; private int item=2; private RotateAnimation animation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_time); setFullScreen(); img_ball = findViewById(R.id.img_ball); translateAnimator(); } private void translateAnimator() { // 属性动画完成平移,真实的改变了控件的属性,发生真实的动画效果 ObjectAnimator txAnimator = ObjectAnimator.ofFloat( img_ball, "translationX", 0, 500 ); ObjectAnimator tyAnimator = ObjectAnimator.ofFloat( img_ball, "translationY", 0, 500 ); txAnimator.setDuration(3000); tyAnimator.setDuration(3000); txAnimator.start(); tyAnimator.start(); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { item--; if (item == 1){ Intent intent = new Intent(TimeActivity.this,MainActivity.class); startActivity(intent); } handler.postDelayed(this,2000); } },2000); } /** * 设置全屏 */ private void setFullScreen() { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); }

//xml

<ImageView android:id="@+id/img_ball" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ball"/>

 

转载请注明原文地址: https://www.6miu.com/read-5038927.html

最新回复(0)