简体   繁体   English

在对父视图进行动画处理时,子视图也对动画进行动画处理

[英]While animating parent view child view also animates

I have a relative layout(parent view) and a button (child view) inside this relative layout.i am applying scale animation on parent view in order to get slide down and slide up animation.but when scale animation is applied to parent view its child view also scales.is there any why to stop child from animation here is my layout code 我在这个相对布局中有一个相对布局(父视图)和一个按钮(子视图)。我在父视图上应用缩放动画以便向下滑动和向上滑动动画。但是当将缩放动画应用于父视图时子视图也可缩放。是否有任何原因可以阻止子级进入动画,这是我的布局代码

<RelativeLayout 


    android:layout_width="300dp"
    android:layout_height="300dp"
    android:layout_marginTop="80px"
    android:id="@+id/txt_help_gest"
    android:background="#111111"

    >

    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/test"

    android:clickable="true"
    android:onClick="toggle_contents1"
    android:text="title" />


    </RelativeLayout>

my scale animation code 我的体重秤动画代码

<?xml version="1.0" encoding="utf-8"?>

<scale
    android:duration="500"
    android:fromXScale="1.0"
    android:fromYScale="0.0"
    android:interpolator="@android:anim/linear_interpolator"
    android:toXScale="1.0"

    android:toYScale="0.5" />

scale to 0.5 means i want my view to scale to half from orignal size but its child is also becoming to half 缩放到0.5表示我希望我的视图从原始大小缩放到一半,但它的子项也在变成一半

my java code 我的java代码

public static void slide_down(Context ctx, View v) {

    Animation a = AnimationUtils.loadAnimation(ctx, R.anim.slidedown);


a.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // TODO Auto-generated method stub
            b.clearAnimation();
        }
    });

    if (a != null) {

        a.reset();

        if (v != null) {

            v.clearAnimation();

            v.startAnimation(a);

        }

    }

}

If you want you parent view to get slide up or down you have to use translate animation instead of scale. 如果要使父视图向上或向下滑动,则必须使用平移动画而不是缩放比例。 Try this (your child view will have original size stil): 尝试以下操作(您的子视图将具有原始大小stil):

<?xml version="1.0" encoding="utf-8"?>
<translate
    android:duration="500"
    android:fromXDelta="100%"
    android:fromYDelta="0%"
    android:interpolator="@android:anim/linear_interpolator"
    android:toXDelta="100%"
    android:toYDelta="50%" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM