【问题标题】:Create a bump effect for a bottom sheet android studio为底部工作表 android studio 创建凹凸效果
【发布时间】:2020-04-27 06:47:55
【问题描述】:

有一个折叠的底部表我希望这个底部表在我想要的时候(当我更新一些数据时)产生一点凹凸效果

您认为最佳做法是什么?玩 set bottomsheetpeeklayoutheight 属性?

我正在使用一个

private BottomSheetBehavior bottomSheetBehavior;

有一个

private NestedScrollView bottomSheetStoreResult;

任何人在其代码中实现了这一点?

提前谢谢大家! :)

【问题讨论】:

    标签: java android effect bottom-sheet bump


    【解决方案1】:

    旧答案 - 见下文

    。 .

    好的,我正在使用处理程序执行此操作,我知道使用它们并不总是一个很好的解决方案,但这里它的任务很轻,持续 1 秒。

    但是效果如我所愿这是最重要的!

    如果你们有更好的解决方案,我仍然想听听你们的意见:

    首先我在 onCreate() 中使用 getViewTreeObserver() 来获取我的底部表格布局的 peekheight。

        bottomSheetPeekLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                bottomSheetPeekLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                peekHeight = bottomSheetPeekLayout.getHeight();
            }
        });
    

    然后,在网络结果中,我只使用了 setPeekHeight,因为有一个 set animation to true 选项可用:

        final Handler h1 = new Handler();
        h1.postDelayed(new Runnable() {
            @Override
            public void run() {
                h1.removeCallbacksAndMessages(this);
                if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED){
                    bottomSheetBehavior.setPeekHeight(peekHeight*3, true);
                final Handler h2 = new Handler();
                h2.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        h2.removeCallbacksAndMessages(this);
                        bottomSheetBehavior.setPeekHeight(peekHeight, true);
                    }
                }, 400);
            }
            }
        }, 600);
    

    。 .

    更新

    。 .

    虽然使用自己的持续时间是一个非常糟糕的主意,但我决定使用 animate() 方法。与上述处理程序答案相比,它更流畅、更美观。

    如果您想使用它,请确保您的底页足够高,以便在动画期间不会在底部创建空白区域进行翻译。

    使用这个:

        bottomSheet.animate()
                .translationYBy(-250)
                .setDuration(300)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        bottomSheet.animate()
                                .translationY(0)
                                .setDuration(300);
                    }
                });
    

    您可以自定义延迟,这样会更简洁 :) 享受吧!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多