问题描述
所以我有这个缩放动画,它应该做的是将视图缩放到全高的70%,然后将其缩放回原始大小。我有两个具有不同startOffsets的比例动画。
So I have this scaling animation and what it's supposed to do is scale the view to 70% of the full height, and then scale it back to the original size. I have two scale animations with different startOffsets.
我遇到的问题是动画开始之前的视图比例。因此,当动画开始时,它们可以使用已经缩小的视图。
The problem I'm having with this is the view scales before the animations even start. So when the animations start, they work with the already-shortened-scaled view.
这是我的动画xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator" >
<scale
android:duration="300"
android:fillAfter="true"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:startOffset="200"
android:toXScale="1.0"
android:toYScale="0.7"
/>
<scale
android:duration="300"
android:fillAfter="true"
android:fromXScale="1.0"
android:fromYScale="0.7"
android:startOffset="1000"
android:toXScale="1.0"
android:toYScale="1.0"
/>
</set>
这就是我所说的动画:
mScaleTop = AnimationUtils.loadAnimation(this, R.anim.scale_top);
mTopView.startAnimation(mScaleTop);
有什么想法吗?感谢您的阅读。
Any ideas? Thanks for reading.
推荐答案
取决于@pskink在评论中的提示
depending on @pskink notice in comments
如果您的动画具有循环模式,则只能将 android:interpolator
属性设置为 @android:anim / cycle_interpolator
,因此您只能使用第一阶段,然后将恢复为原始状态...
if your animation had a cycle mode you can only set android:interpolator
property to @android:anim/cycle_interpolator"
so you can use only the first stage and then will return to orginal status...
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/cycle_interpolator" >
<scale
android:duration="300"
android:fillAfter="true"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:startOffset="200"
android:toXScale="1.0"
android:toYScale="0.7" />
</set>
否则,如果要使用 linear_interpolator
,您还必须从 1.0
而不是从 0.7
缩放高度,因为 1.0
指示当前状态
Otherwise if you want to use linear_interpolator
you have to scale height from also 1.0
and not from 0.7
because the 1.0
indicate to current status
android:fromYScale = 1.0
表示当前状态的 100%
等于原始状态的70%...
android:fromYScale="1.0"
meaning that 100%
of current status and = 70% of orginal status...
所以您必须扩展高度 android:fromYScale = 1.0
到 android:fromXScale = 1.42
so you have to scale height android:fromYScale="1.0"
to android:fromXScale="1.42"
因为: android:fromYScale = 1.0
=原始尺寸的70%,您必须将70的42%等于完整原始尺寸的100%高度...。
because: android:fromYScale="1.0"
=70% from orginal size you have to add 42% of 70 to equal 100% of full orginal height....
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator" >
<scale
android:duration="300"
android:fillAfter="true"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:startOffset="200"
android:toXScale="1.0"
android:toYScale="0.7"
/>
<scale
android:duration="300"
android:fillAfter="true"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:startOffset="1000"
android:toXScale="1.0"
android:toYScale="1.42"
/>
</set>
这篇关于缩放动画会导致视图在开始动画之前缩短的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!