有一个折叠的底板我希望这个底板在我想要的时候产生一点凹凸效果(当我更新一些数据时)
您认为最佳做法是什么?使用 set bottomsheetpeeklayoutheight 属性?
我正在使用一个
private BottomSheetBehavior bottomSheetBehavior;
与
private NestedScrollView bottomSheetStoreResult;
有人在其代码中实现了这一点吗?
谢谢大家 !:)
有一个折叠的底板我希望这个底板在我想要的时候产生一点凹凸效果(当我更新一些数据时)
您认为最佳做法是什么?使用 set bottomsheetpeeklayoutheight 属性?
我正在使用一个
private BottomSheetBehavior bottomSheetBehavior;
与
private NestedScrollView bottomSheetStoreResult;
有人在其代码中实现了这一点吗?
谢谢大家 !:)
. .
好的,我正在与处理程序一起执行此操作,我知道使用它们并不总是一个很好的解决方案,但这里它的任务很轻,持续 1 秒。
但它就像我期待的那样工作,这是最重要的!
如果您有更好的解决方案,我仍然想听听你们的意见:
首先,我在 onCreate() 中使用 getViewTreeObserver() 来获取我的底部表格布局的 peekheight。
bottomSheetPeekLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
bottomSheetPeekLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
peekHeight = bottomSheetPeekLayout.getHeight();
}
});
然后,在网络结果中,我只使用了 setPeekHeight,因为有一个设置动画为 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);
}
});
您可以自定义延迟,它更干净:) 享受!