Android规模视图和重新布局

时间:2014-11-23 13:57:15

标签: android android-layout android-animation android-view

对于模糊的标题,我们深表歉意。我真的不能提出这个问题很少的话。好的,让我描述一下我想要实现的目标。

首先,我有一个包含两个视图的垂直LinearLayout。视图A可见且尽可能大(匹配父级)。对于View BI,将VIEW.GONE设置为默认值。

然后,由某个东西触发,View A将缩放到其大小的一半。并且将通过设置VIEW.VISIBLE来显示视图B.为了使View A和View B具有相同的高度,我在xml中为它们分配了相同的权重。下图说明了我想要实现的内容。

figure

为了缩放视图A,我使用View.ScaleX(0.5f)和View.ScaleY(0.5f)。实际上我以动画的方式实现了scale函数,并在EndAnimation Callback中设置了View B的可见性。

但是无法正确显示视图A和视图B.每个视图的一半被未知的“白色块”掩盖。

我还检查了视图A的高度 - 宽度,在缩放之前和之后,它根本不会改变。

那么有可能实现这样的功能吗?

非常感谢。

1 个答案:

答案 0 :(得分:0)

您想在View A上添加scaleY动画,然后再显示View B吗?绝对可能。我不确定你指的是什么是“白块”。如果需要帮助调试,则应该提供一些代码。

否则,您应该使用像这样的ObjectAnimator:

ObjectAnimator animator = ObjectAnimator.ofFloat(viewA, "scaleY", 1f, 0.5f);
animator.addListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
        viewB.setVisibility(View.VISIBLE);
        // You can display the view b with an animation
        ObjectAnimator.ofFloat(viewB, "alpha", 0f, 1f).start();

        // Remember to reset the scale factor since there will be a re-layout
        viewA.setScaleY(1.0f);
    }
});
animator.start();