TraslationAnimation
我们在制作动画的时候,有时需要将一张图片从左往右,从上往下移动这时候需要使用TranslationAnimation位移动画这个类,new这个类的时候选择带四个参数的构造方法,分别表示图像左上角(X的开始坐标,X的结束坐标,Y的开始坐标,Y的结束坐标),参数的值我们可以指定具体的像素,或者百分比%,但是都会存在屏幕的适配问题,在每种机型上动画的移动距离不同,这是我们可以使用比如XX.getHeight()来获取该控件的高度,移动该控件高度的距离从而解决了不同机型的动画适配问题。
TranslateAnimation animation=new TranslateAnimation(0,0,0,-pic.getHeight());
animation.setDuration(1500);
animation.setFillAfter(false);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
pic.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
linearLayout.startAnimation(animation);
网友评论