【问题标题】:Animate Resize View in Material DesignMaterial Design 中的动画调整视图大小
【发布时间】:2015-01-04 01:25:03
【问题描述】:

在不涉及 layoutParams 的情况下,是否有另一种方法来调整、折叠或展开视图?我在新 Material Design 的一些视频和新的 Android Dialer App 中看到了这些动画。谷歌说材料可以很容易地改变形状、大小、旋转、颜色等……但我什么也找不到。

是否有向后兼容性?

到目前为止,为了调整、折叠或展开视图,我们必须像这样使用 layoutParams,例如:

public static void collapse(final View v) {
final int initialHeight = v.getMeasuredHeight();

Animation a = new Animation()
{
    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        if(interpolatedTime == 1){
            v.setVisibility(View.GONE);
        }else{
            v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
            v.requestLayout();
        }
    }

    @Override
    public boolean willChangeBounds() {
        return true;
    }
};

a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);

}

以下是我希望从新的 Google Android 拨号器应用中获得的示例:

【问题讨论】:

    标签: android resize android-custom-view material-design


    【解决方案1】:

    我认为 ViewPropertyAnimator 是您想要的。 检查此链接http://developer.android.com/guide/topics/graphics/prop-animation.html#view-prop-animator

    这是一个例子:

    view.animate().scaleY(endHeight/initialHeight).start()

    这与您在代码中所做的动画相同

    【讨论】:

    • 使用scaleY(..) 不会影响布局。只有项目的可见尺寸会改变,但布局中视图占用的空间不会改变。
    • 是的,PropertyValuesHolder 会是更好的选择
    猜你喜欢
    • 2015-06-16
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多