import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.SystemClock; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ImageView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private ImageView img; private Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); //跟新UI Toast.makeText(MainActivity.this,"dfdfdfdf",Toast.LENGTH_SHORT).show(); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); method(); new Thread(new Runnable() { @Override public void run() { //线程睡眠3秒等待动画执行完毕 SystemClock.sleep(3000); //发送空消息 handler.sendEmptyMessage(0); } }).start(); } private void method() { PropertyValuesHolder trans = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, 0, 0,300f,300f); PropertyValuesHolder rotate = PropertyValuesHolder.ofFloat(View.ROTATION_Y, 0, 360f); PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat(View.ALPHA, 0, 1f, 0.5f); PropertyValuesHolder scale = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f, 2f); //给img添加了多种动画 组合动画 ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(img, trans, rotate, alpha, scale); //动画时间为3秒 objectAnimator.setDuration(3000); objectAnimator.start(); } private void initView() { img = (ImageView) findViewById(R.id.img); } }
handler进行动画之后的操作
最新推荐文章于 2023-01-08 22:25:19 发布