Closed AnirudhLoya closed 9 years ago
The Listview in bottomsheet showing up to some point ,when i scrolled it reaching to the top,
But i want show the listview according to content ,
Listview with More items not showing full screen,when i scrolled then it is going for fullscreen
help me to made it full screen even with more items,may be the problem because of listview in ui i have listview below of on textview,and bottom it contains two buttons i tried these two bottomSheet.setMinimumHeight(height of screen); bottomSheet.getSheetView().setMinimumHeight(height of screen);
If you are trying to adjust the peek height, I found I had to extend and override bottom sheet.
In the below case, I get the height of my view set in the sheet, or use the maximum height.
@Override
public float getPeekSheetTranslation() {
CartSheetView sheetView = (CartSheetView) getSheetView();
if (sheetView.getScrollHeight() > 0) {
return (getMaxSheetTranslation() < sheetView.getScrollHeight()) ? getMaxSheetTranslation() : sheetView.getScrollHeight() ;
}
if (definedPeekHeight > 0) {
return (getMaxSheetTranslation() < definedPeekHeight) ? getMaxSheetTranslation() : definedPeekHeight ;
} else {
return super.getPeekSheetTranslation();
}
}
And this could be a totally wrong way to handle it, but I also want my scroll view to never be larger than the height of the parent view. To accomplish this I went this route:
in init() edit: This code is in the actual RelativeLayout (or whatever you want to use) view that resides in the sheet (the view that slides up/down into place).
/**
* This is to try and get the scrollView size when available....
*/
ViewTreeObserver viewTreeObserver = itemContainerScrollView.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// hrm... removeOnGlobalLayoutListener
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
itemContainerScrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
itemContainerScrollView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
resizeScroller();
}
});
}
And the actual method resizing
public void resizeScroller() {
// Get the scroller height...
int scrollHeight = itemContainerScrollView.getHeight();
// Get the parent height
View parent = (View) getParent();
int parentHeight = parent.getHeight();
if (scrollHeight > parentHeight) {
itemContainerScrollView.setLayoutParams(
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, parentHeight)
);
this.scrollHeight = parentHeight;
} else {
this.scrollHeight = scrollHeight;
}
}
Oh, you could also override getMaxSheetTranslation and provide a different size.
I think @Anatidae-Project's answers sum this up. @AnirudhLoya can I close this?
how can i override getMaxSheetTranslation ?
Extend BottomSheet.
@Override public float getMaxSheetTranslation() {}
If you're using Android Studio and a bit new to Java, leverage the tools to override methods. It will drop in needed boilerplate. I think command-N on mac and alt-insert on PC.
(Edit, whoever has the handle Override must get a painful amount of spam from mistakes like mine above)
A little bit outdated, but this issue has good index in google search. You can try set LayoutParams with fixed height in pixels. BottomSheetDialog dialog = new BottomSheetDialog(getContext(), getTheme()); dialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 500))
Can you provide some more context? e.g. in its peeked state, collapsed state, what you are trying to accomplish.