gpt4 book ai didi

Android Tween 动画在 startAnimation() 上闪烁

转载 作者:行者123 更新时间:2023-12-02 01:39:35 25 4
gpt4 key购买 nike

我有一个带有两个 ImageView 的框架布局。一个在另一个之上。

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp">

<ImageView
android:id="@+id/post_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true" />

<ImageView
android:id="@+id/double_tap_heart"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:src="@drawable/double_tap_heart"
android:visibility="invisible"/>

</FrameLayout>

我想默认隐藏第二个 ImageView,并在用户双击帖子时将其显示在第一个 ImageView 的顶部,动画持续 1000 毫秒。正是 Instagram 应用程序的工作方式。

这是我的动画 XML

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">

<set
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<scale
android:duration="400"
android:fromXScale="0.3"
android:fromYScale="0.3"
android:toXScale="1.15"
android:toYScale="1.15"
android:pivotX="50%"
android:pivotY="50%"/>
<alpha
android:duration="400"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
<set
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:startOffset="400">
<scale
android:duration="100"
android:fromXScale="1.15"
android:fromYScale="1.15"
android:toXScale="1.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"/>
</set>
<set
android:startOffset="500">
<scale
android:duration="300"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="1.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"/>
</set>
<set
android:interpolator="@android:anim/accelerate_interpolator"
android:startOffset="800" >
<scale
android:duration="200"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="0.2"
android:toYScale="0.2"
android:pivotX="50%"
android:pivotY="50%"/>
<alpha
android:duration="200"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>

</set>

在我调用的 ListViewAdapter 中

ImageView doubleTapHeart = (ImageView) findViewById(R.id.double_tap_heart);
doubleTapHeart.startAnimation(doubleTapHeartAnimation);

每当有人双击帖子时。我面临的问题是 double_tap_heart 可绘制对象闪烁了大约。动画开始前 1 毫秒全尺寸。动画结束后,ImageView 恢复为不可见状态。

如何让 ImageView 只在动画期间显示而没有闪烁效果?我看过其他几篇关于此的帖子,但没有有效的答案。我已经尝试过 setAlpha() 和 setZAdjustment(),但没有任何方法可以消除这种闪烁。

最佳答案

对于那些在自己寻找答案时可能会遇到这个问题的人...

闪烁问题是由于我们正在使用 View Animation 造成的。这是 Android 在 3.0 之前使用的动画系统。 View 动画在本质上更为原始,因为它们将动画应用于 View 的容器。不幸的是,当 View 在动画之前消失或不可见时,这会导致问题。

答案???使用Android新的动画系统Property Animation http://developer.android.com/guide/topics/graphics/prop-animation.html这消除了闪烁的原因是因为它将动画中定义的更改直接应用于您正在使用的 View 的属性。因此名称为“属性”动画...而另一个可以称为“容器”动画。

最佳做法是最初在布局 xml 文件中将 View 的 alpha 设置为 0.0。然后在您的动画中更改 alpha 以使其可见,并在动画结束时将 alpha 更改回 0.0 这样您就不必为使 View 可见/不可见/消失而烦恼。

希望这对其他人有帮助。

关于Android Tween 动画在 startAnimation() 上闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29219689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com