animateLayoutChanges不与嵌套布局的工作呢? [英] animateLayoutChanges does not work well with nested layout?

查看:420
本文介绍了animateLayoutChanges不与嵌套布局的工作呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似下面的嵌套布局:

I have a nested layout like the following:

 <LinearLayout>     <!----Parent layout--->
    <LinearLayout>    <!-----child 1--->
       ...
    </LinearLayout>   <!----child 1 ended--->
    <LinearLayout>    <!-----child 2--->
       ...
    </LinearLayout>   <!----child 2 ended--->
 </LinearLayout>    <!----Parent endded--->

现在我遇到的问题是,因为我的所有的数据项都在孩子1或儿童2 Linaerlayout,如果我添加或删除项目子的LinearLayout将动画与animateLayoutChanges的影响,但父母的布局不会做任何动画。 (我有安卓animatioLayoutChanges设置为true,所有linearlayouts)。特别是我删除之内的孩子1一个项目时的动画效果变得怪异(基本上孩子2会跳起来,而孩子1仍然尽自己的动画)。

The problem I am having now is that since all my data items are within child 1 or child 2 Linaerlayout, if I add or delete a item the child linearlayout will animated with the effect of animateLayoutChanges but the parent layout will not do any animation. (I have android:animatioLayoutChanges set to true for all linearlayouts). Especially when i deleting a item within child 1 the animation effect becomes weird( basically child 2 will jump up while child 1 is still doing its animation).

没有任何人有任何想法如何解决这个问题?

Does anybody have any idea how to solve this?

感谢

更新

不久后,我张贴了这个问题,我发现这对Android的开发者网站上的LayoutTransition的API中。

Shortly after I posted this question, I found this on android developer's site in the LayoutTransition API.

"Using LayoutTransition at multiple levels of a nested view hierarchy may not work due to the interrelationship of the various levels of layout." 

因此​​,没有人有大约建议任何工作这个问题?

So does anyone have any work around suggestions for this issue?

推荐答案

animateLayoutChanges 属性利用 LayoutTransitions 的,该动画在布局的儿童和,从机器人4.0以后,在布局层级祖先一路到树的顶部。在蜂窝,只有布局的孩子们将动画。请参见这个Android开发者博客文章了解详细信息。

The animateLayoutChanges property makes use of LayoutTransitions, which animate both the layout's children and, from Android 4.0 onward, ancestors in the layout hierarchy all the way to the top of the tree. In Honeycomb, only the layout's children will be animated. See this Android Developers Blog post for details.

不幸的是,似乎有目前没有简单的方法有布局的兄弟姐妹反应,其 LayoutTransitions 。你可以尝试使用 TransitionListener 来得到通知时,布局的界限正在被改变,并使用动画师相应地移动同胞的意见。见切特·哈泽的第二个答案在这Google+的帖子

Unfortunately, it seems that there's currently no simple way to have the siblings of a layout react to its LayoutTransitions. You could try using a TransitionListener to get notified when the layout's bounds are being changed, and move the sibling views accordingly using Animators. See Chet Haase's second answer in this Google+ post.

修改 - 原来,那里的的一种方式。在安卓4.1+(API级别16+),可以使用布局过渡类型更改,它在默认情况下禁用。为了使它能够在code:

EDIT - Turns out there is a way. In Android 4.1+ (API level 16+) you can use a layout transition type CHANGING, which is disabled by default. To enable it in code:

ViewGroup layout = (ViewGroup) findViewById(R.id.yourLayout);
LayoutTransition layoutTransition = layout.getLayoutTransition();
layoutTransition.enableTransitionType(LayoutTransition.CHANGING);

那么,在你的榜样,让孩子2布局动画,你需要启用更改布局改造它。当出现在其父的边界发生变化的转变,然后应用。

So, in your example, to have child 2 layout animated, you'd need to enable the CHANGING layout transformation for it. The transformation would then be applied when there is a change in the bounds of its parent.

请参阅这DevBytes影片了解更多详情。

这篇关于animateLayoutChanges不与嵌套布局的工作呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆