優雅的讓TextView 全部展示出來

這裏最主要的是使用到一個類 ValueAnimator 這個類的作用是產生一系列的中間變化值

//   優雅的顯示
    private void visibityHeight(final View view) {
        if (view.getLayoutParams().height <= 0) {
            ValueAnimator animator = ValueAnimator.ofInt(0, dip2px(20));
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    int tempValue = (int) animation.getAnimatedValue();
                    System.out.println("tempValue : " + tempValue);
                    ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
                    layoutParams.height = tempValue;
                    view.setLayoutParams(layoutParams);
                }
            });
            animator.setDuration(500);
            animator.setInterpolator(new AccelerateInterpolator());
            animator.start();
        }
    }
//  優雅的隱藏
   private void goneHeight(final View view) {
        if (view.getLayoutParams().height > 0) {//表示
            ValueAnimator animator = ValueAnimator.ofInt(dip2px(20), 0);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    int tempValue = (int) animation.getAnimatedValue();
                    System.out.println("tempValue : " + tempValue);
                    ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
                    layoutParams.height = tempValue;
                    view.setLayoutParams(layoutParams);
                }
            });
            animator.setDuration(500);
            animator.setInterpolator(new AccelerateInterpolator());
            animator.start();
        }
    }
發佈了55 篇原創文章 · 獲贊 7 · 訪問量 4258
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章