use*_*222 10 animation android translate-animation
我想对角线下的图像进行动画制作,如下图所示.我尝试过翻译动画,但我只能做平行的X轴或平行的Y轴.
但无法弄清楚如何对角地做到这一点.而且我也不确定是否可以通过翻译动画或其他类型的动画来完成.所以请建议我怎么做,或者如果有人能给我一个有用的链接,那么我也会被瞄准.

Dav*_*ini 20
一种方法是使用a AnimatorSet来ObjectAnimator一起玩.
private void animateDiagonalPan(View v) {
AnimatorSet animSetXY = new AnimatorSet();
ObjectAnimator y = ObjectAnimator.ofFloat(v,
"translationY",v.getY(), targetY);
ObjectAnimator x = ObjectAnimator.ofFloat(v,
"translationX", v.getX(), targetX);
animSetXY.playTogether(x, y);
animSetXY.setInterpolator(new LinearInterpolator(1f));
animSetXY.setDuration(300);
animSetXY.start();
}
Run Code Online (Sandbox Code Playgroud)
或者您可以使用自定义View的自定义Property,但在这种情况下,您需要自己计算X和Y的翻译:
final Property<YourView, Float> transProperty = new Property<YourView, Float>(
float.class, "translation") {
@Override
public Float get(YourView) {
return object.getTranslation();
}
@Override
public void set(YourView, Float value) {
object.translate(value);
}
};
private void translate(float value){
setTranslationX(value);
setTranslationY(value);
}
Run Code Online (Sandbox Code Playgroud)
并使用它来动画:
private void animateDiagonalPan(View v) {
ObjectAnimator xy = ObjectAnimator.ofFloat(v,
transProperty, targetValue);
xy.setInterpolator(new LinearInterpolator(1f));
xy.setDuration(300);
xy.start();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11966 次 |
| 最近记录: |