Android - ObjectAnimator设置透视值

时间:2013-08-09 04:58:30

标签: android pivot android-animation scaleanimation

我想要一个相对布局放大,视图的底部应该是固定的 我有一个相对布局 -

private RelativeLayout rlOutdoorSection;

初始化它 -

rlOutdoorSection = (RelativeLayout) findViewById(R.id.rlOutdoorSection);

创建了一个ObjectAnimator -

scaleUpOutdoor = ObjectAnimator.ofFloat(rlOutdoorSection, "scaleY", 1f,
            2.6f);
    scaleUpOutdoor.setDuration(3000);

启动动画 -

scaleDownOutdoor.start();

目前,视图已在视图中心使用透视值进行缩放。

如何确保视图缩放并修复视图的底部?

先谢谢。

1 个答案:

答案 0 :(得分:10)

首先,我们必须计算视图的HEIGHT -

iOutdoorCompressedHeight = rlOutdoorSection.getMeasuredHeight();

使用此height作为必须缩放视图的轴。

rlOutdoorSection.setPivotX(0f);
rlOutdoorSection.setPivotY(iOutdoorCompressedHeight);

这里的技巧可以是获得测量的视图高度 在Activity中计算高度

@Override
public void onWindowFocusChanged(boolean hasFocus)
{
    super.onWindowFocusChanged(hasFocus);
    // Here calculate the height / width
}

FRAGMENT使用全局布局侦听器 -

rlOutdoorSection = (RelativeLayout) vMain
            .findViewById(R.id.rlOutdoorSection);
    ViewTreeObserver vtoOutdoor = rlIndoorSection.getViewTreeObserver();
    vtoOutdoor.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            iOutdoorCompressedHeight = rlOutdoorSection.getMeasuredHeight();
            rlOutdoorSection.setPivotX(0f);
            rlOutdoorSection.setPivotY(iOutdoorCompressedHeight);

        }
    });

希望这会对某人有所帮助。