MultipleBottomSheets is an Android library to implement multiple nested bottom sheets in Android.
Add jcenter() in project level build.gradle.
repositories {
jcenter()
}
Add dependency in app level build.gradle.
dependencies{
implementation 'com.roshaan.multiplebottomsheets:multiplebottomsheets:1.0.1'
}
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.roshaan.multiplebottomsheets.MultipleSheetsContainer
android:id="@+id/sheetContainer"
android:layout_width="0dp"
android:layout_height="490dp"
app:sheetsCount="5"
app:sheetsHeightDifference="50dp"
app:sheetsTopCornerRadius="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
- sheetsCount: Number of sheets to display, default value is 3.
- sheetsHeightDifference Defines the height difference between sheets, default value is 30dp.
- sheetsTopCornerRadius Defines the top corner radius for each sheet, default value is 0dp.
- Maximum expanded height for the first sheet is equal to the height of MultipeSheetsContainer, each below sheet's height is calculated by subtracting minimumSheetsHeightDifference from the height of the sheet above it.
- Minimum collpased height for the first sheet is calculated by this formula (sheetsCount * sheetsHeightDifference).
Associate fragment with each sheet using code.
sheetContainer.addFragment(0, Sheet1Fragment())
sheetContainer.addFragment(1, Sheet2Fragment())
sheetContainer.addFragment(2, Sheet3Fragment())
sheetContainer.addFragment(3, Sheet4Fragment())
sheetContainer.addFragment(4, Sheet5Fragment())
sheetContainer.lockedSheetIndex = 2
- sheetsContainer.lockedSheetIndex locks the sheet at the specified index and sheets below that sheet. By default all sheets are unlocked, sheets lock can be removed by setting sheetContainer.lockedSheetIndex=REMOVE_LOCK.
- Currently MultipleSheetsContainer supports layout_height="match_parent" or explicitly defined height, layout_height="wrap_content" is not supported.
- MultipleSheetsContainer must be attached to the bottom of the root layout.