该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
//点击图片,启动动画效果
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Animation transAnim = getTransAnimation(v,-200);
v.startAnimation(transAnim);
}
});
//位移动画
public Animation getTransAnimation(final View v,final float dy) {
//创建动画
TranslateAnimation transAnim = new TranslateAnimation(0.0f,0.0f,0.0f,dy);
transAnim.setDuration(1000);//设置动画执行时间
transAnim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
int width = v.getWidth();
int height = v.getHeight();
int left = v.getLeft();
int top = v.getTop()+(int)(dy);
v.clearAnimation();
v.layout(left,top, left+width, top+height);
}
});
return transAnim;
}