有人知道Android动画吗?我想要创建如下内容:如何在Android中创建移动/调整动画大小?
- 我在设备屏幕的中心有一个大图像;
- 这个图像变得很小(通过动画),并转到我的设备屏幕的一角;
它像在这种波纹管顺序:
任何提示将是非常赞赏!提前致谢!
有人知道Android动画吗?我想要创建如下内容:如何在Android中创建移动/调整动画大小?
它像在这种波纹管顺序:
任何提示将是非常赞赏!提前致谢!
使用ViewPropertyAnimator
,使用方法如scaleXBy()
和translateYBy()
。您通过在API Level 11+上的View
上致电animate()
获得ViewPropertyAnimator
。如果您支持较旧的设备,则NineOldAndroids可提供接近工作的回送。
您可能还希望阅读:
我与同步旋转和运动的一类。这是昂贵的,但它适用于所有API版本。
public class ResizeMoveAnimation extends Animation {
View view;
int fromLeft;
int fromTop;
int fromRight;
int fromBottom;
int toLeft;
int toTop;
int toRight;
int toBottom;
public ResizeMoveAnimation(View v, int toLeft, int toTop, int toRight, int toBottom) {
this.view = v;
this.toLeft = toLeft;
this.toTop = toTop;
this.toRight = toRight;
this.toBottom = toBottom;
fromLeft = v.getLeft();
fromTop = v.getTop();
fromRight = v.getRight();
fromBottom = v.getBottom();
setDuration(500);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float left = fromLeft + (toLeft - fromLeft) * interpolatedTime;
float top = fromTop + (toTop - fromTop) * interpolatedTime;
float right = fromRight + (toRight - fromRight) * interpolatedTime;
float bottom = fromBottom + (toBottom - fromBottom) * interpolatedTime;
RelativeLayout.LayoutParams p = (LayoutParams) view.getLayoutParams();
p.leftMargin = (int) left;
p.topMargin = (int) top;
p.width = (int) ((right - left) + 1);
p.height = (int) ((bottom - top) + 1);
view.requestLayout();
}
}
感谢CommonsWare。当然,这有很大的帮助! – mthama