// 펼칠경우

slideView(targetView, targetView.getLayoutParams().height, 200);

 

// 숨길경우

slideView(targetView, targetView.getLayoutParams().height, 0);

public static void slideView(View view,
                                 int currentHeight,
                                 int newHeight) {

        ValueAnimator slideAnimator = ValueAnimator
                .ofInt(currentHeight, newHeight)
                .setDuration(500);

        /* We use an update listener which listens to each tick
         * and manually updates the height of the view  */

        slideAnimator.addUpdateListener(animation1 -> {
            Integer value = (Integer) animation1.getAnimatedValue();
            view.getLayoutParams().height = value.intValue();
            view.requestLayout();
        });

        // 시작 / 끝 / 취소 / 반복 동작에 대한 Listener
        slideAnimator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(@NonNull Animator animator) {

            }

            @Override
            public void onAnimationEnd(@NonNull Animator animator) {

            }

            @Override
            public void onAnimationCancel(@NonNull Animator animator) {

            }

            @Override
            public void onAnimationRepeat(@NonNull Animator animator) {

            }
        });

        /*  We use an animationSet to play the animation  */

        AnimatorSet animationSet = new AnimatorSet();
        animationSet.setInterpolator(new AccelerateDecelerateInterpolator());
        animationSet.play(slideAnimator);
        animationSet.start();
    }

'Android(Java)' 카테고리의 다른 글

[Java] Lottie LoadingHUD Dialog  (1) 2024.03.15
[Java] enum  (0) 2024.03.15
[Java] ProgressDialog 로딩 시스템 UI  (1) 2024.02.27
[Java] Parcelable을 이용한 객체 Intent 전달  (0) 2024.02.27
[Java] Intent 데이터 전달 방식  (0) 2024.02.27

+ Recent posts