【问题标题】:Scale animation - How to stop child view animation缩放动画 - 如何停止子视图动画
【发布时间】:2014-05-21 12:14:25
【问题描述】:

我在这个布局中有一个布局(父视图)和一个文本视图(子视图)。在父视图上应用缩放动画,但是当缩放动画应用于父视图时,它的子视图也会缩放。有没有办法阻止子动画?包括代码

布局文件

<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();

}

【问题讨论】:

  • 请发布您的代码
  • 在问题中包含代码
  • 如果一个容器(线性布局)是动画的,它所包含的所有子元素都会动画。但是,您可以使用不同的 XML 结构,可能使用相对布局,以获得您想要的效果。

标签: android animation scale viewgroup objectanimator


【解决方案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();

【讨论】:

    猜你喜欢
    • 2014-02-22
    • 1970-01-01
    • 2013-04-17
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    相关资源
    最近更新 更多