1

I am using an AdaptorViewFlipper.

Its methods setInAnimation() and setOutAnimation() expect the resource ID of a XML with an ObjectAnimator.

I want the animation to scale & fade the view simultaneously.

I define this scale_in_animator.xml (for the sake of example I only post the In animation, the Out one is just the inverse)

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:propertyName="transitionScaleIn"
    android:valueFrom="0"
    android:valueTo="1"
    android:valueType="floatType" />

And the view returned by the AdaptorViewFlipper's adapter includes this function:

public void setTransitionScaleIn(float value) {
    setScaleX(2-value);
    setScaleY(2-value);
    setAlpha(value);
}

However, nothing happens. setTransitionScaleIn is not ever called.

Am I doing something wrong?

4

1 回答 1

1

来自AdapterViewFlipper的源代码:

  .
  .
  // We wrap the new view in a FrameLayout so as to respect the contract
  // with the adapter, that is, that we don't modify this view directly
  FrameLayout fl = getFrameForChild();
  .
  .

所以AdapterViewFlipper将每个子视图包装在 aFrameLayout中,所以我只需要扩展 AdapterViewFlipper 并覆盖这个函数:

FrameLayout getFrameForChild() {
    return new FrameLayoutAnimable(getContext());
}

当然,还要创建使用所有 setXXXXXX 方法FrameLayoutAnimable扩展的类。FrameLayout

NOTE->getFrameForChild是一个包方法,所以你的扩展AdapterViewFlipper必须在android.widget包中。

于 2014-09-12T17:36:51.763 回答