【发布时间】:2016-10-30 19:53:03
【问题描述】:
我想在我的BottomBar 上方显示BottomSheet。所以我必须编写自定义BottomSheetbehavior,这将把我的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)。
谁能帮我修复我的代码,或者至少给我一些提示我到底做错了什么或者我错过了什么?
【问题讨论】:
标签: android android-layout material-design android-coordinatorlayout bottom-sheet