我能得到
吗?RelativeLayout的坐标x和y
虽然我从
动画MATCH_PARENT到WARP_CONTENT
所以我只想让x和y为其中的另一个视图设置动画
因为我有很多RelativeLayout
作为孩子,当我将父母从MATCH_PARENT
更改为WARP_CONTENT
时,孩子的位置发生了变化,并且mabye不在屏幕上,所以我想考虑x和y如果父级为MATCH_PARENT
或WARO_CONTENT
答案 0 :(得分:0)
怎么样?
RelativeLayout mlayout = findViewById(R.id.yourID);
float x = mlayout.getX();
float y = mlayout.getY();
修改:来自Resizing layouts programmatically (as animation)
所以你需要最终的高度和宽度,也许你可以使它成为invisbile,改为WRAP_CONTENT,测量新的高度和宽度,改变回来,使用上面的代码创建可见和动画大小到新的高度和宽度。 不幸的是,不知道更好的方式。
然后设置动画宽度:
实例化ResizeAnimation
ResizeAnimation resizeAnimation = new ResizeAnimation(
view,
targetHeight,
startHeight,
targetWidth,
startWidth
);
resizeAnimation.setDuration(duration);
view.startAnimation(resizeAnimation);
ResizeAnimation
类应该看起来像这样
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;
}
}