Android 底部View 平滑显示

布局




    


    

Android 底部View 平滑显示_第1张图片


第一种 简短位移动画

final View bot = findViewById(R.id.bot);
        Button but = findViewById(R.id.but);

        bot.setTranslationY(600);

        but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bot.animate()
                        .translationY(0)
                        .setDuration(2000)
                        .withLayer()
                        .start();
            }
        });

 final View bot = findViewById(R.id.bot);
        Button but = findViewById(R.id.but);

        bot.post(new Runnable() {

            @Override
            public void run() {
                final ViewGroup.LayoutParams layoutParams = bot.getLayoutParams();
                int height = layoutParams.height;
                layoutParams.height = 0;

                bot.setLayoutParams(layoutParams);

                valueAnimator = ValueAnimator.ofInt(0, height);
                valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        int mAnimatorValue = (int) valueAnimator.getAnimatedValue();
                        layoutParams.height = mAnimatorValue;
                        bot.setLayoutParams(layoutParams);
                    }
                });

            }
        });

        but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                valueAnimator.start();
            }
        });

 

Android 底部View 平滑显示_第2张图片

 

你可能感兴趣的:(群里大佬学习)