int mScreenWidth = getResources().getDisplayMetrics().widthPixels;//屏幕宽
int mScreenHeight = getResources().getDisplayMetrics().heightPixels;//屏幕高
TranslateAnimation(平移动画)
ABSOLUTE
int w1 = v.getWidth();//Button控件的宽度
int h1 = v.getHeight();//Button控件的高度
TranslateAnimation t1 = new TranslateAnimation(
Animation.ABSOLUTE, 0, Animation.ABSOLUTE, w1,
Animation.ABSOLUTE, 0, Animation.ABSOLUTE, h1);
t1.setDuration(1000);
v.startAnimation(t1);
RELATIVE_TO_PARENT
int w2 = v.getWidth();//Button控件的宽度
int h2 = v.getHeight();//Button控件的高度
float xRatio = w2 * 1.0f / mScreenWidth;//计算控件的宽度占父控件的宽度的比率
float yRatio = h2 * 1.0f / mScreenHeight;//计算控件的高度度占父控件的宽度的比率
TranslateAnimation t2 = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, xRatio,
Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, yRatio);
t2.setDuration(1000);
v.startAnimation(t2);
RELATIVE_TO_SELF
TranslateAnimation t3 = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1); t3.setDuration(1000); v.startAnimation(t3);RotateAnimation(旋转动画)
ABSOLUTE
int w4 = v.getWidth();//Button控件的宽度
int h4 = v.getHeight();//Button控件的高度
RotateAnimation r1 = new RotateAnimation(0, 360,
Animation.ABSOLUTE, w4,
Animation.ABSOLUTE, h4);
r1.setDuration(1000);
v.startAnimation(r1);
RELATIVE_TO_PARENT
int w5 = v.getWidth();//Button控件的宽度
int h5 = v.getHeight();//Button控件的高度
float xPivot = w5 * 1.0f / mScreenWidth;//计算控件的宽度占父控件的宽度的比率
float yPivot = h5 * 1.0f / mScreenHeight;//计算控件的高度度占父控件的宽度的比率
RotateAnimation r2 = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_PARENT, xPivot,
Animation.RELATIVE_TO_PARENT, yPivot);
r2.setDuration(1000);
v.startAnimation(r2);
RELATIVE_TO_SELF
RotateAnimation r3 = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 1,
Animation.RELATIVE_TO_SELF, 1);
r3.setDuration(1000);
v.startAnimation(r3);
ScaleAnimation(缩放动画)
ABSOLUTE
int w6 = v.getWidth();//Button控件的宽度
int h6 = v.getHeight();//Button控件的高度
ScaleAnimation s1 = new ScaleAnimation(0, 1, 0, 1,
Animation.ABSOLUTE, w6 / 2,
Animation.ABSOLUTE, h6 / 2);
s1.setDuration(1000);
v.startAnimation(s1);
RELATIVE_TO_PARENT
ScaleAnimation s3 = new ScaleAnimation(0, 1, 0, 1,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
s3.setDuration(1000);
v.startAnimation(s3);



