如何在不使用android中的任何库的情况下创建Sliding Up Panel

时间:2015-12-11 11:00:41

标签: android animation android-animation layoutparams

在单一视图中,我想在recyclerview中显示地图和地点列表,因此我使用权重来划分布局。现在它将根据地点recyclerview滚动显示地图半屏和列表半屏我要在谷歌地图中显示该地点的位置。在滚动的同时我想让我的列表大80%之后,当他们使用地图时它应该变成正常大小这一切都有效。现在我想要的是像谷歌音乐一样增加高度的动画。

崩溃代码:

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

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);

扩展代码:

v.measure(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.MATCH_PARENT);
    final int targetHeight = (height / 100) * 40;

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1
                    ? AbsoluteLayout.LayoutParams.MATCH_PARENT
                    : (int) (targetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);

动画流畅不来,有人可以帮助我

0 个答案:

没有答案