我想在我的
以下是我尝试实现的内容:
到目前为止,这个解决方案还没有完全生效。我可以使用
BottomBar
上方显示BottomSheet
。因此,我必须编写自定义的BottomSheet
behavior
,将我的BottomSheet
放在BottomBar
上方 - BottomBar
具有shy behavior
(滚动时隐藏)。以下是我尝试实现的内容:
public class BottomSheetBehavior<T extends View> extends android.support.design.widget.BottomSheetBehavior<T> {
public BottomSheetBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
return dependency instanceof BottomBar;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
// This will set the Y of my bottom sheet above the bottom bar every time BottomBar changes its position
child.setY(dependency.getY() - child.getHeight());
// But I also have to modify the bottom position of my BottomSheet
// so the BottomSheet knows when its collapsed in its final bottom position.
child.setBottom((int) dependency.getY() - dependency.getHeight());
return false;
}
}
到目前为止,这个解决方案还没有完全生效。我可以使用
setY()
方法将 BottomSheet
放在 BottomBar
上方。但是扩展和折叠的功能存在问题。因此,我尝试使用 setBottom()
方法修改 BottomSheet
的底部,但也不起作用。可能是因为单位错误(px vs dp)。请问有人能帮我修复代码或者至少给我一些提示,到底哪里出了问题或者我漏掉了什么?