Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android为宽度和高度相对值设置动画_Android_Android Layout_Android Animation_Android Xml - Fatal编程技术网

android为宽度和高度相对值设置动画

android为宽度和高度相对值设置动画,android,android-layout,android-animation,android-xml,Android,Android Layout,Android Animation,Android Xml,我能拿到票吗 相对坐标的x和y 当我从 将父对象与扭曲内容匹配 所以我只想用x和y来制作另一个视图的动画 因为我有很多RelativeLayout作为子对象,当我将父对象从MATCH\u parent更改为WARP\u CONTENT时,子对象的位置发生了变化,并且可能不在屏幕上,所以我考虑在设置动画时取父对象的x和y,减去子对象的位置,如果父对象是,则使子对象处于相同的位置MATCH\u PARENT或WARO\u CONTENT怎么办 RelativeLayout mlayout = fin

我能拿到票吗

相对坐标的x和y

当我从

将父对象与扭曲内容匹配

所以我只想用x和y来制作另一个视图的动画 因为我有很多
RelativeLayout
作为子对象,当我将父对象从
MATCH\u parent
更改为
WARP\u CONTENT
时,子对象的位置发生了变化,并且可能不在屏幕上,所以我考虑在设置动画时取父对象的x和y,减去子对象的位置,如果父对象是,则使子对象处于相同的位置
MATCH\u PARENT
WARO\u CONTENT

怎么办

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

float x = mlayout.getX();
float y = mlayout.getY();
编辑:来自

因此,您需要最终的高度和宽度,也许您可以使其不可见,更改为包裹内容,测量新的高度和宽度,更改为后退,使其可见,并使用上面的代码将大小设置为新的高度和宽度。 不幸的是,我不知道更好的办法

然后设置宽度动画:

实例化
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;
    }
}

好的,但是我怎样才能将高度和宽度从
MATCH\u PARENT
设置为
CONTENT\u WARP