How apply translate animation with scale animation on a view. I have to move a view to another view location with zoom out simultaneously.
How scale a view from its position to another view position (Second view is not fixed)?
startView - view that translate
finishView - where animation finish.
**Code **
private void startAnimation(View startView, View finishView) {
int startX = startView.getLeft() + startView.getWidth() / 2;
int startY = startView.getTop() + startView.getHeight() / 2;
int startViewLocation[]=new int[2];
startView.getLocationInWindow(startViewLocation);
int finishViewLocation[]=new int[2];
finishView.getLocationInWindow(finishViewLocation);
int endX = finishViewLocation[0];
int endY=finishViewLocation[1];
System.out.println("statX " + startX + " " + (startView.getLeft() + startView.getWidth() / 2));
System.out.println("statY " + startY+" "+(startView.getTop() + startView.getHeight() / 2));
System.out.println("endX " + endX+" "+finishViewLocation[0]);
System.out.println("endY " + endY+" "+finishViewLocation[1]);
TranslateAnimation translateAnimation = new TranslateAnimation(0, 0,
TranslateAnimation.ABSOLUTE, endX, 0, 0,
TranslateAnimation.ABSOLUTE, endY);
ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f,
0.0f);
AnimationSet set = new AnimationSet(true);
set.addAnimation(translateAnimation);
set.addAnimation(scaleAnimation);
set.setFillAfter(true);
set.setDuration(2000);
set.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
});
startView.startAnimation(set);
}