Issue
I am trying to hide a certain view whenever the bottom-sheet is expanded, but the code that checks the state only gets executed one time. How do i make the program constantly check the state of the bottom-sheet and hide the view(grid_opt) whenever the bottom sheet is expanded.
class dashboard : AppCompatActivity() {
private lateinit var bottomSheetBehavior: BottomSheetBehavior<ConstraintLayout>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.dashboard_main)
bottomSheetBehavior = BottomSheetBehavior.from(persistent_bottom_sheet)
bottomSheetBehavior.state = STATE_EXPANDED
if ( bottomSheetBehavior.state == STATE_EXPANDED){
grid_opt.isVisible = false;
}else if(bottomSheetBehavior.state== STATE_COLLAPSED){
grid_opt.isVisible= true;
}
Solution
This can be done by adding bottomsheetcallback
bottomSheetBehavior.addBottomSheetCallback(object :
BottomSheetBehavior.BottomSheetCallback() {
override fun onSlide(bottomSheet: View, slideOffset: Float) {
}
override fun onStateChanged(bottomSheet: View, newState: Int) {
grid_opt.isVisible = when (newState) {
BottomSheetBehavior.STATE_EXPANDED -> false
BottomSheetBehavior.STATE_COLLAPSED -> true
else -> false
}
}
})
Answered By - Abinab Dangi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.