Bottom Sheet Android- Scrolling issue

淺唱寂寞╮ 提交于 2019-12-04 07:10:57

Instead of using scrollview you can use NestedScrollView that works better with CoordinatorLayout make sure to use app:layout_behavior="@string/appbar_scrolling_view_behavior" for smooth scrolling of content inside NestedScrollView

mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
                mBottomSheetBehavior.setPeekHeight(0);
            }
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        }
    });

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.btn_negetive: {
            mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
            mBottomSheetBehavior.setPeekHeight(Constants.PEEK_HEIGHT);
            mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
            break;
        }
        case R.id.btn_positive: {
            //some code
        }
    }
}

the above solution worked for me using this link: https://code.tutsplus.com/articles/how-to-use-bottom-sheets-with-the-design-support-library--cms-26031

Try setting:

app:behavior_hideable="true"

in your xml file and in your activity add something like:

else if (newState == BottomSheetBehavior.STATE_HIDDEN{
    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
    mBottomSheetBehavior.setPeekHeight(80); }

This will allow your bottom sheet dialog to be pulled down immediately if you wanted to.

Try this, Hope it will help

Put this after initilizing the views

  ViewCompat.postOnAnimation(coordinatorLayout, new Runnable() {
            @Override
            public void run() {
                ViewCompat.postInvalidateOnAnimation(coordinatorLayout);
            }
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!