等待其他视图animation结束

我有以下布局片段:

   

如您所见,在LinearLayout animateLayoutChanges设置为true ,因此当向其添加项目时,它会为添加设置animation。 这没关系,但删除有问题。 如果我删除一个项目,animation仍然可以正常播放,但下面的TextView立即popup并且不会等待animation完成。 我如何实现这一点,甚至更好,使TextViewanimation与LinearLayoutanimation同步?

您可以通过以下方式从视图中检索LayoutTransition :

 mLinearLayout = findViewById(R.id.myLayout); LayoutTransition layoutTransition = mLinearLayout.getLayoutTransition(); layoutTransition.addTransitionListener(new TransitionListener(){ @Override public void endTransition(LayoutTransition arg0, ViewGroup arg1, View arg2, int arg3) { switch(arg2.getId()){ //.... } } @Override public void startTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) { switch(view.getId()){ //.... } }}); 

这不是一个答案,而是一个随时可用的代码片段,您可以尝试检查正在发生的事情。

 mContainer = (ViewGroup) v.findViewById(R.id.container); if (Build.VERSION.SDK_INT >= 11) { mLayoutTransition = mContainer.getLayoutTransition(); if (mLayoutTransition != null) { mLayoutTransition.addTransitionListener(new LayoutTransition.TransitionListener() { @Override public void startTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) { Log.d("\n\n startTransition: in "+container+" view "+view+" type "+ descr(transitionType)); } @Override public void endTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) { Log.d("\n\n endTransition: in "+container+" view "+view+" type "+ descr(transitionType)); } String descr(int transitionType) { String[] m = new String[]{"CHANGE_APPEARING","CHANGE_DISAPPEARING","APPEARING","DISAPPEARING"}; return "" + transitionType + ": " + m[transitionType&3] + " changing="+( transitionType&LayoutTransition.CHANGING); } }); } } 

对我来说,容器视图是一个LinearLayout ,感兴趣的事件是:

 public void endTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) { // UI thread if (transitionType == LayoutTransition.DISAPPEARING) { // start 2nd animation, it will be done while another view is moved } }