设为首页 加入收藏

TOP

Android属性动画之ObjectAnimator控制
2015-02-25 16:15:27 来源: 作者: 【 】 浏览:31
Tags:Android 属性 动画 ObjectAnimator 控制

该项目的的布局文件只有两个控件:ImageView和Button,在这里就不在赘述了,下面我们来看一下activity的实现:


?


public class TwoActivity extends Activity{
? ? private Button button;private ImageView imageView;
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? button = (Button)findViewById(R.id.Button);
? ? ? ? imageView = (ImageView)findViewById(R.id.imageView);
? ? ? ? button.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View view) {
? ? ? ? ? ? ? ? ObjectAnimator animator = new ObjectAnimator().ofFloat(imageView, "alpha", 0F, 1F);
? ? ? ? ? ? ? ? animator.setDuration(1000);
? ? ? ? ? ? ? ? animator.addListener(new Animator.AnimatorListener() {
? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void onAnimationStart(Animator animator) {
? ? ? ? ? ? ? ? ? ? ? ? //开始动画事件
? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(TwoActivity.this, "动画开始", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void onAnimationEnd(Animator animator) {
? ? ? ? ? ? ? ? ? ? ? ? //结束动画事件
? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(TwoActivity.this, "动画结束", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void onAnimationCancel(Animator animator) {
? ? ? ? ? ? ? ? ? ? ? ? //取消事件
? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void onAnimationRepeat(Animator animator) {
? ? ? ? ? ? ? ? ? ? ? ? //重复事件
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? animator.start();
? ? ? ? ? ? }
? ? ? ? });
? ? }
}


在这里重点为大家介绍一下ObjectAnimator的addListener()方法,可以看到,实现这个方法时需要实现其内部的四个内置方法,我们经常使用onAnimationEnd()方法,用来为用户呈现动画结束后的控制。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android属性动画之ValueAnimation 下一篇Android属性动画之ObjectAnimator

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: