属性动画设置延迟后,如果在未开始前取消,会执行onAnimationStart方法,特此记录
2016-06-30 14:31
429 查看
public class AnimatorDelayTestActivity extends AppCompatActivity { private View mTextView; private ObjectAnimator translationY; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.animator_delay); mTextView = findViewById(R.id.animator_test); } public void start(View view) { translationY = moveView(mTextView, "translationY", 0, mTextView.getHeight(), 5000); translationY.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); Log.i("onAnimationUpdate", "start方法"); } }); translationY.start(); } public void cancel(View view) { translationY.cancel(); } private ObjectAnimator moveView(View view, final String attr, float start, float end, int delay) { ObjectAnimator move = ObjectAnimator.ofFloat(view, attr, start, end); move.setDuration(1000); move.setStartDelay(delay); return move; } } <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.lizheng_ds3.myapplication.MainActivity"> <TextView android:id="@+id/animator_test" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="动画测试" android:textSize="20dp" /> <Button android:id="@+id/start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/animator_test" android:layout_marginTop="50dp" android:onClick="start" android:text="开始" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/start" android:layout_marginTop="50dp" android:onClick="cancel" android:text="取消" /> </RelativeLayout>
@Override public void cancel() { // Only cancel if the animation is actually running or has been started and is about // to run AnimationHandler handler = getOrCreateAnimationHandler(); if (mPlayingState != STOPPED || handler.mPendingAnimations.contains(this) || handler.mDelayedAnims.contains(this)) { // Only notify listeners if the animator has actually started if ((mStarted || mRunning) && mListeners != null) { if (!mRunning) { // If it's not yet running, then start listeners weren't called. Call them now. notifyStartListeners(); } ArrayList<AnimatorListener> tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone(); for (AnimatorListener listener : tmpListeners) { listener.onAnimationCancel(this); } } endAnimation(handler); } }
private void notifyStartListeners() { if (mListeners != null && !mStartListenersCalled) { ArrayList<AnimatorListener> tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone(); int numListeners = tmpListeners.size(); for (int i = 0; i < numListeners; ++i) { tmpListeners.get(i).onAnimationStart(this); } } mStartListenersCalled = true; }
不知道为什么这么设计,但是源码里面就是这么写的,用的时候注意一下
相关文章推荐
- ubuntu 默认防火墙安装、启用、查看状态
- 专题四1010
- python使用random函数生成随机数
- servlet/filter/listener/interceptor区别与联系
- 371. Sum of Two Integers
- unity3d对象添加了碰撞体以后OnMouseDown事件
- 新的开始,新的挑战
- mysql进阶:复制表结构、表数据技巧
- jenkins插件 查看job下次运行时间
- jquery制作的多种选项卡效果
- 浅谈爬虫
- 178 无法连接远程服务器mysql数据库
- linux系统生产者-消费者,读者-写者,哲学家就餐 C语言实现
- Ruby FFI 入门教程
- [转]借助VoiceOver来破解优秀App的实现方式
- 让vim成为VS的编辑器
- C++ 类的继承五(类继承中的static关键字)
- [置顶] 物联网体系系统学习笔记
- bzoj 1937 最小生成树【费用流】
- webstorm12破解方法