有没有办法为 ImageView 的裁剪设置动画?
例如,ImageView 是 720 x 480。我想用动画切掉底部的像素行,直到 ImageView 完全消失。我只能在启用 onclicklistener 时将图像向上移动,并使其透明,这没关系,但不是设计师要求的。
有没有办法为 ImageView 的裁剪设置动画?
例如,ImageView 是 720 x 480。我想用动画切掉底部的像素行,直到 ImageView 完全消失。我只能在启用 onclicklistener 时将图像向上移动,并使其透明,这没关系,但不是设计师要求的。
ValueAnimator anim = ValueAnimator.ofInt(myImageView.getMeasuredHeight(), 0);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int val = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = myImageView.getLayoutParams();
layoutParams.height = val;
myImageView.setLayoutParams(layoutParams);
}
});
anim.setDuration(1000);
anim.start();
我从这里得到了代码,只是把它改成了高度:ObjectAnimator animate LinearLayout width
假设您只想剪掉高度,使用ObjectAnimator
将创建这样一个自定义裁剪高度动画,首先您需要指定getHeight()
和setHeight()
方法,然后使用ObjectAnimator
.
public float getHeight() { ... }
public void setHeight(float h) { ... }
ObjectAnimator heightAnim= ObjectAnimator.ofFloat(yourImageView, "height", heightBegin, heightEnd);