Android-缩放其父视图组后为子视图设置动画

Android-缩放其父视图组后为子视图设置动画,android,animation,view,invalidation,viewgroup,Android,Animation,View,Invalidation,Viewgroup,我有一个父视图(RelativeLayout)和一个子视图。我使用FillAfter=true增加父视图的比例,然后设置子视图的alpha动画。在子视图alpha的动画期间,仅对覆盖视图原始位置的视图部分设置动画。在我看来,子视图动画的帧失效似乎没有考虑父视图的缩放变换。 我想知道我是如何做到这一点的——能够对视图层次结构的任意层进行动画/变换的能力 RelativeLayout rootLayout = FindViewById<RelativeLayout>(Resource.I

我有一个父视图(RelativeLayout)和一个子视图。我使用FillAfter=true增加父视图的比例,然后设置子视图的alpha动画。在子视图alpha的动画期间,仅对覆盖视图原始位置的视图部分设置动画。在我看来,子视图动画的帧失效似乎没有考虑父视图的缩放变换。 我想知道我是如何做到这一点的——能够对视图层次结构的任意层进行动画/变换的能力

RelativeLayout rootLayout = FindViewById<RelativeLayout>(Resource.Id.RootLayout);
rootLayout.SetClipChildren(false);

RelativeLayout parentLayout = new RelativeLayout(this);
parentLayout.SetClipChildren(false);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(500, 500);
layoutParams.LeftMargin = (this.Window.WindowManager.DefaultDisplay.Width - 500) / 2;
layoutParams.TopMargin = (this.Window.WindowManager.DefaultDisplay.Height - 500) / 2;
parentLayout.LayoutParameters = layoutParams;
parentLayout.SetBackgroundColor(new Color(255, 0, 0, 255));
rootLayout.AddView(parentLayout);

View childView = new View(this);
RelativeLayout.LayoutParams viewLayoutParams = new RelativeLayout.LayoutParams(200, 200);
viewLayoutParams.LeftMargin = 150;
viewLayoutParams.TopMargin = 150;
childView.LayoutParameters = viewLayoutParams;
childView.SetBackgroundColor(new Color(0, 255, 0, 255));
parentLayout.AddView(childView);

Button growButton = FindViewById<Button>(Resource.Id.growButton);
growButton.Click += delegate
    {
        ScaleAnimation scaleAnimation = new ScaleAnimation(1, 1.2f, 1, 1.2f, parentLayout.Width / 2, parentLayout.Height / 2);
        scaleAnimation.Duration = 1000;
        scaleAnimation.FillAfter = true;
        parentLayout.StartAnimation(scaleAnimation);
    };

Button fadeButton = FindViewById<Button>(Resource.Id.fadeButton);
fadeButton.Click += delegate
    {
        AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0.5f);
        alphaAnimation.Duration = 1000;
        alphaAnimation.FillAfter = true;
        childView.StartAnimation(alphaAnimation);
    };
RelativeLayout rootLayout=findviewbyd(Resource.Id.rootLayout);
rootLayout.SetClipChildren(false);
RelativeLayout parentLayout=新的RelativeLayout(此);
parentLayout.SetClipChildren(false);
RelativeLayout.LayoutParams LayoutParams=新的RelativeLayout.LayoutParams(500500);
layoutParams.LeftMargin=(this.Window.WindowManager.DefaultDisplay.Width-500)/2;
layoutParams.TopMargin=(this.Window.WindowManager.DefaultDisplay.Height-500)/2;
parentLayout.LayoutParameters=layoutParams;
SetBackgroundColor(新颜色(255,0,0,255));
rootLayout.AddView(parentLayout);
视图子视图=新视图(此视图);
RelativeLayout.LayoutParams viewLayoutParams=新的RelativeLayout.LayoutParams(200200);
viewLayoutParams.LeftMargin=150;
viewLayoutParams.TopMargin=150;
childView.LayoutParameters=viewLayoutParams;
SetBackgroundColor(新颜色(0,255,0,255));
parentLayout.AddView(childView);
Button growButton=FindViewById(Resource.Id.growButton);
增长按钮。单击+=委派
{
ScaleAnimation ScaleAnimation=新的ScaleAnimation(1,1.2f,1,1.2f,parentLayout.Width/2,parentLayout.Height/2);
scaleAnimation.Duration=1000;
scaleAnimation.FillAfter=真;
parentLayout.StartAnimation(scaleAnimation);
};
按钮fadeButton=FindViewById(Resource.Id.fadeButton);
fadeButton.单击+=委派
{
AlphaAnimation AlphaAnimation=新的AlphaAnimation(1,0.5f);
持续时间=1000;
alphaAnimation.FillAfter=真;
childView.StartAnimation(字母动画);
};
以下是单击“增长”按钮和“淡入”按钮的结果图片:

这个场景是人为设计的-在我的项目中,父视图应用了多种类型的动画,并且它覆盖了draw方法,以便在动画未运行时将这些转换应用于自身。此父视图包含多个子视图,这些子视图本身以多种方式设置动画(包括通过TransitionDrawable设置的背景色动画)

我认识到有很多方法可以解决这个问题——例如,将子对象与父对象分离,分别设置它们的动画,并将AlphaAnimation子类化,以使用ApplyTransformation中的当前比例值更新子视图变换——但当外推到更复杂的动画时,这就变得荒谬了。我很确定我会通过TransitionDrawable遇到另一面墙,背景动画是通过TransitionDrawable绘制的——不同于动画,我不知道什么时候我有机会变换最终会失效的区域(最后一种方法是回到覆盖AnimationDrawable)

必须有更好的方法来做到这一点,我觉得我一定错过了什么。我不认为这些类型的动画非常复杂;在WP和iOS上,它们是微不足道的。我该走哪条路?我需要创建自己的动画线程并处理自己的失效吗?我应该使用SurfaceView吗

我的目标是姜饼,所以我没有玩过地产动画——但我很好奇他们是否会让这更容易?如果转换目标能使开发变得更简单,那么它可能是一种选择