为底层的android工作室创建凹凸效果



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

你认为最好的做法是什么?是否正在玩设置的底部页面eeklayyoutheight属性?

我正在使用

private BottomSheetBehavior bottomSheetBehavior;

带有

private NestedScrollView bottomSheetStoreResult;

有人在代码中实现过这一点吗?

提前感谢大家!:(

旧答案-见下文

.

好吧,我是和处理程序一起做这件事的,我知道使用它们并不总是一个很好的解决方案,但这里它的任务很轻,持续1秒。

但是它就像我一直期待的那样工作这是最重要的!

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

首先,我在onCreate((中使用getViewTreeObserver((来获取我的底部布局的窥视高度。

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);
}
});

你可以自定义延迟,它更干净:(享受吧!

最新更新