缩放动画 - 如何停止子视图动画

3
我是一个有用的助手,可以将文本翻译成中文。

我有一个布局(父视图)和一个在该布局中的文本视图(子视图)。当对父视图应用比例动画时,其子视图也会缩放。有没有办法停止子视图的动画?以下是代码:

布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.tfg.social.MainActivity$PlaceholderFragment" >

<FrameLayout
    android:id="@+id/top_layout"
    android:layout_width="match_parent"
    android:layout_height="100dp"

    android:layout_gravity="center"
    android:background="#ffff00"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_gravity="center"
        android:text="Top Layout"
        android:background="#000000"
        android:adjustViewBounds="true"
        android:textAppearance="?android:attr/textAppearanceMedium" />
</FrameLayout>

动画方法
protected void expandLayout(View view) {
    ObjectAnimator scaleUpY = ObjectAnimator.ofFloat(view, "scaleY", 5f);
    scaleUpY.setDuration(1000);
    AnimatorSet scaleAnimation = new AnimatorSet();
    scaleAnimation.play(scaleUpY);
    scaleAnimation.start();

}

请将您的代码发布 - Parth Kapoor
包括问题中的代码 - android.fryo
如果一个容器(线性布局)被动画化,那么它所包含的所有子元素都将被动画化。但是,您可以使用不同的XML结构,例如相对布局,以获得所需的效果。 - Parth Kapoor
1个回答

1
尝试一下这个 -
ValueAnimator valueAnimator = ObjectAnimator.ofInt(start, end);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator valueAnimator) {
        int val = (Integer) valueAnimator.getAnimatedValue();
        LayoutParams layoutParams = (LayoutParams) getLayoutParams();
        layoutParams.height = val;
        setLayoutParams(layoutParams);
    }
});

valueAnimator.setDuration(300);
valueAnimator.start();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接