public class Timer extends AppCompatActivity { private TextView tv; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.timer); tv= (TextView) findViewById(R.id.textView); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final ValueAnimator valueAnimator=ValueAnimator.ofInt(0,100); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { Integer value= (Integer) animation.getAnimatedValue(); tv.setText(String.valueOf(value)); } }); valueAnimator.setInterpolator(new LinearInterpolator()); valueAnimator.setDuration(10000); valueAnimator.start(); } }); } }
代码库/计时器/ValueAnimator
最新推荐文章于 2021-03-12 14:14:18 发布