[카카오페이 메인 클론코딩 2] onslide , onStateChanged, setalpha(블러처리/ 흐리게 하면서 사라지게함), scaleX(화면이 커지고 작아지고)구현

2021. 1. 10. 22:21모바일/Android_Java

onslide , onStateChanged

bottomSheetLayout을 슬라이드하게 될 경우

  • onslide의 offset이 0~1값으로 callback된다.
  • 0 : 초기상태
  • 1: expaned상태
  • 0과1사이에 적당한 animation과 scale , margin을통해 원하는 위치에 이미지들을 배치하고 구현할 수 있다.
        BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(mBottomSheet);
        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
        bottomSheetBehavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                // Called every time when the bottom sheet changes its state.
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                transitionBottomSheetBackgroundColor(slideOffset);
                FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) ivBarcode.getLayoutParams();
                layoutParams.topMargin = (int) (dpToPx(250)*slideOffset);
                ivBarcode.setLayoutParams(layoutParams);
                ivQR.animate().scaleX(slideOffset).scaleY(slideOffset).setDuration(0).start();

            }
        });

            private void transitionBottomSheetBackgroundColor(float slideOffset) {
        int colorFrom = getResources().getColor(R.color.color_1d1d1d);
        int colorTo = getResources().getColor(R.color.colorPrimary);
        Drawable alpha = ivQR.getDrawable();
        alpha.setAlpha((int) (slideOffset*255f));
//        mBottomSheet.setBackgroundColor(interpolateColor(slideOffset,
//                colorFrom, colorTo));
    }

구현 화면

first