属性动画 插值器 demo

xiaoxiao2021-02-28  30

package com.example.propertyanimdemo; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.TextView; public class ThirdActivity extends AppCompatActivity implements View.OnClickListener { /** * 位移 */ private Button mBtTrans; /** * 旋转 */ private Button mBtRotate; /** * 渐变 */ private Button mBtAlpha; /** * 缩放 */ private Button mBtScale; /** * Hello World! */ private TextView mTv; /** * 组合 */ private Button mBtZuhe; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_third); initView(); } private void initView() { mBtTrans = (Button) findViewById(R.id.btTrans); mBtTrans.setOnClickListener(this); mBtRotate = (Button) findViewById(R.id.btRotate); mBtRotate.setOnClickListener(this); mBtAlpha = (Button) findViewById(R.id.btAlpha); mBtAlpha.setOnClickListener(this); mBtScale = (Button) findViewById(R.id.btScale); mBtScale.setOnClickListener(this); mTv = (TextView) findViewById(R.id.tv); mBtZuhe = (Button) findViewById(R.id.btZuhe); mBtZuhe.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { default: break; case R.id.btTrans: trans(); break; case R.id.btRotate: rotate(); break; case R.id.btAlpha: alpha(); break; case R.id.btScale: scale(); break; case R.id.btZuhe: zuhe(); break; } } public void zuhe() { PropertyValuesHolder trans = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, 0, 200f); PropertyValuesHolder rotate = PropertyValuesHolder.ofFloat(View.ROTATION_Y, 0, 180f); PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat(View.ALPHA, 0, 1f, 0.5f); PropertyValuesHolder scale = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f, 2f); //给mTv添加了多种动画 ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(mTv, trans, rotate, alpha, scale); objectAnimator.setDuration(3000); objectAnimator.start(); } private void trans() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mTv, View.TRANSLATION_X, 0, 200f); objectAnimator.setDuration(3000); objectAnimator.start(); } private void rotate() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mTv, View.ROTATION_Y, 0, 180f); objectAnimator.setDuration(3000); objectAnimator.start(); } private void alpha() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mTv, View.ALPHA, 0, 1f, 0.5f); objectAnimator.setDuration(3000); objectAnimator.start(); } private void scale() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mTv, View.SCALE_Y, 2f); objectAnimator.setDuration(3000); objectAnimator.start(); } }
转载请注明原文地址: https://www.6miu.com/read-2619361.html

最新回复(0)