-1

can i get the

coordinate x and y of RelativeLayout

while i animate its from

MATCH_PARENT to WARP_CONTENT

so i just want the x and y for animate another view inside it because i have many RelativeLayout as childeren and when i change the parent from MATCH_PARENT to WARP_CONTENT the position of child changed and mabye be out of screen so i think about take the x and y of parent while animate and minus the child position this make child in same position if parent be MATCH_PARENT or WARO_CONTENT

medo
  • 439
  • 1
  • 8
  • 22

1 Answers1

0

What about

RelativeLayout mlayout = findViewById(R.id.yourID);

float x = mlayout.getX();
float y = mlayout.getY();

Edit: from Resizing layouts programmatically (as animation)

So you need the final height and width, maybe you can make it invisbile, change to WRAP_CONTENT, measure new heigth and width, change back, make visible and animate size with code above to new height and width. Dont know a better way unfortunately.

Then animate width:

InstantiateResizeAnimation

ResizeAnimation resizeAnimation = new ResizeAnimation(
     view, 
     targetHeight, 
     startHeight,
     targetWidth,
     startWidth
); 
resizeAnimation.setDuration(duration); 
view.startAnimation(resizeAnimation);

ResizeAnimation class should look like this

public class ResizeAnimation extends Animation {
    final int targetHeight;
    final int targetWidth;
    View view;
    int startHeight;
    int startWidth;

    public ResizeAnimation(View view, int targetHeight, int startHeight, targetWidth, int startWidth) {
        this.view = view;
        this.targetHeight = targetHeight;
        this.startHeight = startHeight;
        this.targetWidth = targetWidth;
        this.startWidth = startWidth;
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        int newHeight = (int) (startHeight + targetHeight * interpolatedTime);
        int newWidth= (int) (startWidth + targetWidth * interpolatedTime);

        view.getLayoutParams().height = newHeight;
        view.getLayoutParams().width = newWidth;
        view.requestLayout();
    }

    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
    }

    @Override
    public boolean willChangeBounds() {
        return true;
    }
}
Community
  • 1
  • 1
Lucker10
  • 402
  • 3
  • 15
  • ok but how can i animate thats height and width from `MATCH_PARENT` to `CONTENT_WARP` – medo Jul 05 '16 at 23:23