6

我有一组两个动画,两个动画都使用过冲插值器一起运行

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:interpolator="@android:anim/overshoot_interpolator" >

    <translate
        android:duration="6000"
        android:fromXDelta="100%" android:toXDelta="0%" />

    <scale
        android:duration="6000"
        android:fromXScale="1.0" android:toXScale="0.6"
        android:pivotX="0"
        android:fromYScale="1.0" android:toYScale="1.0"
        android:repeatCount="1"
        android:repeatMode="reverse" />
</set>

我希望translate动画过冲,scale动画加速。
我试图这样做,但它不起作用:

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

    <translate
        android:interpolator="@android:anim/overshoot_interpolator"
        android:duration="6000"
        android:fromXDelta="100%" android:toXDelta="0%" />

    <scale
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="6000"
        android:fromXScale="1.0" android:toXScale="0.6"
        android:pivotX="0"
        android:fromYScale="1.0" android:toYScale="1.0"
        android:repeatCount="1"
        android:repeatMode="reverse" />
</set>

对于在单个对象上执行的所有动画,似乎只有一个插值器可以在给定时间处于活动状态。

4

3 回答 3

15

这只是猜测工作。我记得其中一个AnimationSet构造函数可以接受一个参数,即shareInterpolator

从参数的名称来看,在您的情况下,这可能应该设置为 false。现在,它应该使用默认的“值”。这个默认值很可能是正确的,因为尽管您为每个动画指定了不同的插值器,但您的动画没有不同的插值器。

为了确认,AnimationSet 的源代码有以下行来为 shareInterpolator 赋值(来自 xml):

setFlag(PROPERTY_SHARE_INTERPOLATOR_MASK, 
        a.getBoolean(com.android.internal.R.styleable.AnimationSet_shareInterpolator
             , true));

这显然意味着如果未指定此布尔值,它将默认为 true。


解决方案

为了解决你的问题,我想你应该使用这个“R.styleable.AnimationSet_shareInterpolator”来指定它。这仅意味着添加 到您的元素android:shareInterpolator="false" <set>

于 2013-04-10T07:09:14.240 回答
3

我把动画分开,把一个放在一个上ImageView,另一个放在RelativeLayout包含图像视图的一个上。

译者

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

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate
            android:interpolator="@android:anim/overshoot_interpolator"
            android:duration="6000"
            android:fromXDelta="100%" android:toXDelta="0%" />

</set>

标量

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

    <scale
            android:interpolator="@android:anim/accelerate_interpolator"
            android:duration="6000"
            android:fromXScale="1.0" android:toXScale="0.6"
            android:pivotX="0"
            android:fromYScale="1.0" android:toYScale="1.0"
            android:repeatCount="1"
            android:repeatMode="reverse" />
</set>

xml

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/previousItem"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:onClick="goToPreviousItem"
                    android:layout_margin="@dimen/float_from_edges"
                    android:layout_width="wrap_content"
            >
        <ImageView android:id="@+id/previousItemArrow"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:background="@drawable/arrow_left"
                />
    </RelativeLayout>

以及煽动它的源代码:

RelativeLayout previousItemButton = (RelativeLayout)findViewById(R.id.previousItem);
    ImageView myButton = (ImageView)findViewById(R.id.previousItemArrow);
    Animation translator =
            AnimationUtils.loadAnimation(this, R.anim.translator);
    myButton.startAnimation(translator);

    Animation scalor =
            AnimationUtils.loadAnimation(this, R.anim.scalor);
    previousItemButton.startAnimation(scalor);

我觉得它看起来很不错。我不确定你希望得到什么效果。

于 2013-04-10T02:34:25.120 回答
1
This xml works with both interpolators check this


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

    <translate
        android:interpolator="@android:anim/overshoot_interpolator"
        android:fromXDelta="100%" android:toXDelta="0%"
        android:duration="500" />

    <scale
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromXScale="1.0" android:toXScale="0.6"
        android:pivotX="0"
        android:fromYScale="1.0" android:toYScale="1.0"
        android:repeatCount="1"
        android:repeatMode="reverse"
        android:startOffset="500"
        android:duration="1000" />
</set>
于 2013-04-16T12:11:28.143 回答