5

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

private RelativeLayout rlOutdoorSection;

初始化它 -

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

创建了一个 ObjectAnimator -

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

开始动画 -

scaleDownOutdoor.start();

目前,视图正在使用视图中心的枢轴值进行缩放。

如何确保在视图底部固定的情况下缩放视图?

提前致谢。

4

1 回答 1

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);

        }
    });

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

于 2013-08-12T07:00:02.117 回答