是否可以在 Android 4.x 中向 View.animate().* 添加自定义属性?
Android 4.x 提供了 View.animate(),它允许对多个属性进行动画处理。 喜欢:
View.animate().alpha(0.5f).setDuration.start();
我想向该对象添加自定义属性,例如:
CustomView.animate().xyz(0.1f).setDuration.start();
最佳答案
您可以使用自定义动画来做到这一点:
public class CustomAnim extends Animation {
private CustomView mLayout;
private float finalVal;
private float startVal;
public CustomAnim(CustomView layout, float finalVal) {
this.mLayout = layout;
this.finalVal = finalVal;
this.startVal = layout.xyz();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
mLayout.setXYZ(interpolatedTime * (finalVal - startVal) + startVal);
}
@Override
public boolean willChangeBounds() {
return true;
}
}
或者,如果您的属性有 getter 和 setter 方法,例如 setXYZ getXYZ,您可以使用 property animation
关于Android 添加自定义属性到 View.animate().*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13995330/