0

How can i get new position of view after animation it ?

if(animationCompeleted == 1)
{
    return;
}

if(animationCounter != 0)
{
    this.width = this.width + 1.f;
    this.heigh = this.heigh + 1.f;
}
final ScaleAnimation scale = new ScaleAnimation(this.width, this.width + 1.0f, this.heigh, this.heigh + 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1.0f);
scale.setDuration(1000);
scale.setFillAfter(true); 
scale.setFillEnabled(true);
scale.setAnimationListener(new Animation.AnimationListener()
{
    @Override
    public void onAnimationStart(Animation arg0) 
    {

        animationCompeleted = 1;
        animationCounter++;
    }           
    @Override
    public void onAnimationRepeat(Animation arg0) 
    {
        animationCompeleted = 2;
    }           
    @Override
    public void onAnimationEnd(Animation arg0) 
    {
        animationCompeleted = 2;
        //I want to get new position of imageView for comparing with another view(detection going-on it)


    }
});     
imageView.startAnimation(scale);

I want to know when my imageView near to another view.
How can i check it ?
How can i get new X and Y or Height and Width after animation?
I'm tring to get them in onAnimationEnd , but it's static values , it's not change after animation ending ..
Sorry for grammer

3 Answers3

2

try getLocationOnScreen method.

int[] locationOnScreent = new int[2];
yourView.getLocationOnScreen(locationOnScreent);
// locationOnScreent[0] = x
// locationOnScreent[1] = y
Liran Peretz
  • 580
  • 8
  • 11
0

To get dimension of a view, use View.getLayoutParams().height and View.getLayoutParams().width

To get position, to have to cast LayoutParams to MarginLayoutParams and get leftMargin/topMargin/rightMargin/bottomMargin

Hugo Gresse
  • 17,195
  • 9
  • 77
  • 119
  • i'm getting same values on iew.getLayoutParams().height before and after animcation –  Dec 17 '14 at 15:23
0

The main confusion here, is that you have animated a REPRESENTATION OF THE VIEW, not the view itself. Hence, the coordinates of the view after the animation never changed.

Also, the setFillAfter(true) parameter does not interfere with the process. setFillAfter(true) still affects the REPRESENTATION OF THE VIEW only.

Pablo Alfonso
  • 2,317
  • 1
  • 18
  • 24