动画没有的ViewGroup儿童动画 [英] Animate viewgroup without animating children

查看:222
本文介绍了动画没有的ViewGroup儿童动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个自定义的ViewGroup和m开始实施的动画地合计的ViewGroup他。我遇到的问题是,我需要的ViewGroup才能够没有它的孩子被同样的动画动画制作动画。

i have built a custom viewgroup and m beginning to implement animations tot his viewgroup. the problem i am having is that i need the viewgroup to be able to animate without it's children being animated by the same animation.

让我们说我缩放的ViewGroup 2倍大小,但我仍想保留孩子在相同的尺寸(因此装修更多的孩子进入的ViewGroup)。

Lets say i am scaling the viewgroup to 2x size, but i still want to keep children at the same size (thus fitting more children into the viewgroup).

现在我打电话动画如下:

Right now i am calling the animation as follows:

    ScaleAnimation expandAnimation =  new ScaleAnimation(1,2,1,2);
    this.startAnimation(expandAnimation);

在此先感谢! :)

Thanks in advance! :)

推荐答案

您不能直接做你正在寻求与旧的Andr​​oid动画API做什么。你已经注意到了一个限制 - 即缩放组还包括儿童

You can't directly do what you're seeking to do with the old Android animation API. You've already noticed one limitation - that scaling the group also includes the children.

第二个局限是,旧的Andr​​oid动画API不仅影响视觉渲染你的动画项目,只为当时的动画是活动的。换句话说,它实际上并不改变在视图布局方面的大小或有问题的项目的定位。它只是暂时使得它以不同的方式。因此,例如,动态显示按钮从X在屏幕上移动Ÿ,你需要运行的动画,那么当动画完成使用布局的API实际上是重新定位按钮。

The second limitation is that the old Android animation API only affects the visual render of the item you're animating, and only for the time the animation is active. In other words, it doesn't actually alter the size or positioning of the item in question in terms of view layout. It only temporarily renders it a different way. So for instance, to animate a button moving from x to y across the screen, you would need to run the animation, then when the animation completes actually reposition the button using the layout APIs.

也许做你找什么方法是:

Probably the way to do what you're looking for is:


  1. 纳入一个额外的ViewGroup
    小部件布局,定位的
    和尺寸在顶部的小部件
    包含真正的项目。
    最初,它是无形的。


  2. 可见并播放动画。

  3. 当动画完成后,隐藏
    额外的部件,然后调整自己的真实
    通过的LayoutParams部件的ViewGroup
    并添加额外的项目。

  4. 您会
    可能需要调整这个一般
    轮廓,使效果外观
    光滑。 (例如,调整的背景下真正的ViewGroup删除从屏幕上的ViewGroup假之前)。

在Android的蜂窝3.0引入了新的,更灵活的动画API,但不幸的是,如果你的目标2.x设备(即手机)是不可用的。希望一旦新API的主流,这将是更容易。

Android introduced a newer, more flexible animation API in 3.0 Honeycomb, but unfortunately it's not available if you're targeting 2.x devices (i.e., phones). Hopefully this will be easier once the new APIs are mainstream.

这篇关于动画没有的ViewGroup儿童动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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