Reputation: 3605
Can we create a layout where we have a recyclerview over the top of a hidden bottomsheet view such that whenever the bottom sheet slides up and expands, the recyclerview aligns titself just above the bottom sheet and not hide behind it.
Upvotes: 0
Views: 1792
Reputation:
Yes, you can do this. You just have to use the BottomSheetCallback on your BottomSheetBehavior, like this:
bottomSheetBehavior = BottomSheetBehavior.from(yourLayoutWithBottomSheetBehavior);
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) yourRecyclerView.getLayoutParams();
layoutParams.height = bottomSheet.getTop();
yourRecyclerView.setLayoutParams(layoutParams);
yourRecyclerView.requestLayout();
});
In the onSlide method you always get the current top of the bottom sheet if you change state or drag it.
Upvotes: 2
Reputation: 3472
I have wrapped my content view inside an another view ( rootContent ) only for the scope to get the height, but you can get it in a better way. Then in the BottomSheetCallback
mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if(newState == BottomSheetBehavior.STATE_COLLAPSED){
content.getLayoutParams().height = rootContent.getHeight();
}else {
content.getLayoutParams().height = rootContent.getHeight() - bottomSheet.getHeight();
}
content.requestLayout();
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
Upvotes: 0
Reputation: 8834
Yes you can acheive this . Just make RelativeLayout as parent layout then add include your view/layout in it, and assign property alignParentBottom= "true". Then include your RecyclerView and add layout_above="included_layout_id"
Upvotes: -1